A site with fast page load speed is really what every site owner wants. The most benefit is better user experience. But beside that, do you know that it’s also good in terms of search engine ranking? Let’s say for Google, webpages with better loading time will rank better in Google SERPS.
One of the technique to do this for your WordPress site is to host images on a separated sub-domain. By default, images of your WordPress site are hosted in the same main domain of the site. This slow downs your page speed. Because, almost all the browsers create maximum 2 to 4 connections when downloading a page from the web server. So if your pages contain more than one images then it is wise to host those images in another domain so that the browser can download the images in parallel with your main domain.
Then, how to host images of WordPress on a subdomain?
Fortunately, WordPress supports and allows to host images on a subdomain. Right now, you’ll know how to host your website post images in a sub-domain along with the old images which were hosted on the main domain.
1. Create a sub-domain
Most of the time, people host their blog on a shared/VPN hosting environment, and arm with a control panel, which is usually cPanel.
In cPanel, find the Domains control panel:
Click on Subdomains and create a new subdomain, fill in whatever subdomain as you want, let’s say: upload and document root is upload:
This is just a typical case to create a subdomain. In reality, it may depend on your hosting provider. And another note is about your domain name server, if you manage name server of your domain outside the hosting provider, you’ll have to add a new A-record of subdomain to your hosting IP.
2. Change WordPress default image upload folder
For WordPress version less than 3.5, you can easily go to admin page, Settings >> Media, then you’ll found the Uploading Files setting to configure upload folder and URL path.
However, from release of 3.5 this option has been removed from Media Setting . Luckily there are ways to do this. The easiest way is to bring back this option by using plugin WP Original Media Path.
This plugin brings the old option back. You can just leave it there after finishing the path setup, or uninstall it safely as WordPress won’t remove those options until you make them as blank. So, if you are a user of WP 3.5 or higher version, just install the above plugin and get your job done. Once done, uninstall the plugin.
From now on, your newly posted images are hosted in the subdomain, URL of images in new articles are also the new subdomain based, but old ones are unchanged.
3. Update old post images location
Old post images location are usually in ~/public_html/wp-content/uploads/ of your hosting. The subdomain location is supposed to be ~/public_html/upload/ . Just copy all files/folders from old to new location first.
Now update content of all old posts to reflect new location of images. Open phpmyadmin tool in cPanel:
Select your WP database, and SQL tab, execute below sql command:
UPDATE wp_posts SET post_content = REPLACE(post_content,'http://www.yourdomain.com/wp-content/uploads/','http://upload.yourdomain.com/')
To update the images links in the media library run the following sql command:
UPDATE wp_posts SET guid = REPLACE(guid,'http://www.yourdomain.com/wp-content/uploads/','http://upload.yourdomain.com/')
That’s is, enjoy your WP with better performance and search engine optimized.
Leave a Reply