I have a site where I used http://example.com, but if I change my site URL to http://example.co.uk or http://examplesite.co.uk which are all same site.

If I changed anything in the above urls it should override theme url.

Currently it is showing from the database value.

I used

define('WP_HOME',    'http://' . $_SERVER['HTTP_HOST'] );

define('WP_SITEURL', 'http://' . $_SERVER['HTTP_HOST'] );

define( 'WP_CONTENT_URL', 'http://' . $_SERVER['HTTP_HOST'].'/');

but for theme &plugin url it is not working it shows http://example.co.uk

I want as http://example.com if user types the same

  • Please always care about formatting your questions properly. Thanks.
    – kaiser
    Sep 17, 2013 at 12:41
  • This should work (technically at least, same site at multiple domains is bad idea for SEO and stuff) form what I remember. Can you access admin at alternate URLs and do you see domain changing in Settings > General ?
    – Rarst
    Sep 17, 2013 at 12:45
  • I've had a similar requirement to fulfill a few months back. You might care to refer to this excellent answer. Sep 17, 2013 at 12:50
  • thanks for answering. but it is working for bloginfo('url') & not for bloginfo('template_url'). Any ideas?
    – Balas
    Sep 17, 2013 at 13:09
  • can you tell me also for plugins url. Except plugin url all are working fine. Thanks a lot!
    – Balas
    Sep 17, 2013 at 14:32

3 Answers 3


In a comment I pointed you to an existing answer that I figured would solve your problem.

You replied

thanks for answering. but it is working for bloginfo('url') & not for bloginfo('template_url'). Any ideas?

The answer I pointed you to is easily adaptable for that:

In your wp-config.php file, after (!) require_once ABSPATH . 'wp-settings.php'; do the following:

function wpse114490_set_template_uri( $dir )
    if ( ! empty( $_SERVER['HTTP_HOST'] ) ) {
        $domain = $_SERVER['HTTP_HOST'];
        $dir = str_replace( 'example.com', $domain, $dir );
   return $dir;
add_filter( 'template_directory', 'wpse114490_set_template_uri' );
add_filter( 'template_directory_uri', 'wpse114490_set_template_uri' );
add_filter( 'stylesheet_directory', 'wpse114490_set_template_uri' );
add_filter( 'stylesheet_directory_uri', 'wpse114490_set_template_uri' );

This is assuming that example.com is the value set in your settings/DB.


Use the relocate method:


(Also, if you haven't, replace the URL in MySQL by using http://interconnectit.com/products/search-and-replace-for-wordpress-databases/)


Instead of $_SERVER['HTTP_HOST'] write hard coded value and check if it is working.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.