Override WordPress theme url

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.

Read More

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

Related posts

3 comments

  1. 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.

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

Comments are closed.