According to Google’s Search Engine Optimization Starter Guide images should be placed in one folder rather than being scattered about your folder hierarchy.
[su_custom_gallery source=”media: 2864″ width=”354″ height=”570″ title=”always” class=”hidden-xs alignright”]
WordPress when installed is set to “Organise my uploads into month- and year-based folders” under the Dashboard/Settings/Media page. Unless you are running a blogging site with many users adding content I find the long tree to be hard to work with, especially when you are trying to find images from an FTP Client.
It’s a good idea to turn this feature off for business and personal sites and it will make your images easier to find and manage.
The Search Engine Optimization Starter Guide also says that image file names and ALT text should be optimised to make it easier for image search projects like Google Image Search to better understand your images.
Google would like all of your images in one place. To do this open your
wp-config.php file and enter the following lines:
/*Change the default image storage folder for SEO purposes */ define( 'UPLOADS', ''.'images' );
This will change the image folder from
You can now copy your images across including all of those year and month sub folders.
If you clear the “Organise my uploads into month- and year-based folders” option it will only work for uploads that follow. Older posts will have their images organised into years and months.
An easy way to do this is to log on to your server with an FTP Client like Filezilla for example. Navigate to the
C:\Users\public_html\wp-content\uploads\, go to that pictures folder where you will see all the other month/year folders.
/imagesfolder on the website.
/imagesfolder on your computer to
If you go to your WordPress site you will notice that the older posts with their images stored in the year and month folders will not display. The WordPress database still contains the old references for each post.
Open up phpMyAdmin from your CPanel account and open the database for the website. Browse the
wp_postmeta table. In it there is data for every parameter relating to each post. We are only interested in the
Using the following SQL filter the data to get the following:
SELECT * FROM [your database name].wp_postmeta WHERE `meta_key` = '_wp_attached_file'
meta_value column contains the image references relative to the
UPLOADS value set in the
If you only have a few it’s easier to edit by hand the incorrect entries by removing the year and month and leaving only the image file name. For example
If there are a lot of entries it’s easier to use some SQL to do it for you, as follows. Before running back up your table by using the Export option in phpMyAdmin.
UPDATE [your database name].wp_postmeta SET `meta_value`= SUBSTR(`meta_value`,9) WHERE `meta_key` = '_wp_attached_file' AND `meta_value` LIKE '20__/%';
The SUBSTR function returns the supplied string from the 9th character on-wards. The LIKE command uses wildcard characters “%” (any characters) and “_” (only one character) to grab the records that have “2012/” etc, at the start.
Once the SQL has run check that the
meta_value field is showing the correct data and then test your site checking that the images are showing correctly.
Voila! Now your image folder conforms to Google standards.