Host Images on a Subdomain in Wordpress 3.6

0 comment 56 views

Today I’m going to tell you how to host images in a sub-domain your website running on wordpress. Not everyone knows why one should do this. So first let me tell you why a webmaster should host images of his wordpress website in a subdomain.

When you visit a website, the browser downloads a maximum of 4 files from the website in parallel. Now if your webpage has many images, the browser will take time in downloading the contents of the website as it has to download both files and images from a single domain. If you make a separate domain (here as subdomain) then you can make the browser download files as 8 files in parallel. That means you can theoretically make the loading time of the website decrease to half. The concept here is to create a content delivery network (cdn) for you wordpress website.

There is also another way of making use of high speed cdn and that too for free for wordpress. We will cover it next time.

[alert]So let’s begin. But first you will need to back up your website completely including the database.[/alert]

 

1. Create a subdomain:

host_images_subdomain_wordpress (1)

Go to your Cpanel and create a subdomain like “cdn.yoursite.com” and forward /point this domain to www.yoursite.com/wp-content/uploads

 

2. Install “WP Original Media Path” plugin

If you are using the old Wordpress i.e. version less than 3.6, then you don’t need to install this plugin. But if you are running wordpress version 3.6.1 or higher you need to install this plugin as never version of Wordpress doesn’t have this option in it. Download the plugin and activate it.

 

3. Change the Image Upload location in wordpress

host_images_subdomain_wordpress (2)

Go to Settings > Media

There you will see two options under “Uploading Files”

a) Store uploads in this folder – delete everything in it

b) Full URL path to files – use “http://cdn.yoursite.com” there.

All your website image uploads will still be uploaded in the default location i.e. “wp-content/uploads”, it’s only that we will call them through a subdomain now.

 

4. Edit Database

Now the database needs to be edited so that the old posts will also call the images through the subdomain. If you do it individually, it will be a hectic task.

We will make it easy.

Go to Cpanel > PhpMyAdmin > your wordpress database > SQL

host_images_subdomain_wordpress (3)

Here you will need to run a query in it so that all older posts will change their image url to the new created subdomain.

[alert]NOTE: Take a backup of the database before proceeding. We will not be responsible for anything that happens from now on. It’s always better to take a backup of the db first.[/alert]

You will need to paste the following code in the box and press GO

UPDATE wp_posts SET post_content =
REPLACE(post_content,'http://www.yourdomain.com/wp-content/uploads/',
'http://cdn.yourdomain.com/')

[alert variation=”alert-info”]P.S. Change the above domain name with your real domain.[/alert]

host_images_subdomain_wordpress (4)

That’s it. You have successfully hosted your images in a subdomain and increased the page speed by about 20 – 30%. It also helps in increasing the rankings of your website in Google.

If you feel that this is beyond your abilities you might like to check this post to call images from other website for free.

Leave a Comment


Search

About Me

Jane Taylor

Jane Taylor

Passionate interior designer who love sharing knowledge and memories.
More About Me

Newsletter

Subscribe To Our Newsletter for new blog posts, tips & ideas. Let's stay updated!

Top Selling Multipurpose WP Theme

About Us

The Vortex Code

The Vortex Code

Our mission is simple: to make complex concepts accessible, ignite curiosity, and inspire innovation through our blogs and tutorials.

Newsletter

Subscribe To Our Newsletter for new blog posts, tips & ideas. Let's stay updated!

© 2013-23 TheVortexCode. All Right Reserved.