I know it seems to be a strange ask here but hear me out. I have a client who has several subdomains for different countries, such as us.example.com and uk.example.com. I want to change one or two pages of a wordpress website when there is a certain subdomain entered.

Before anyone asks I have mentioned having the different options selectable in the main site but they would rather have it this way.

I could always just have another wordpress install, or put it under a multi-site but if one can do it this way that would be great.

Thanks in advance!

  • Is this a multi-site installation?
    – fuxia
    Apr 18, 2013 at 8:54
  • No, my idea was to have apache point all the domains to the same wordpress install and to be able to change the content of certain pages based on the url, thus not needing a mutli-site but just needing several extra pages. Apr 18, 2013 at 8:55

1 Answer 1


Just check the current host:

add_filter( 'the_content', 'domain_dependent_content' );

function domain_dependent_content( $content )
    // get_the_ID() will return the current post ID if you need 
    // more information about the current page.

    if ( 'page' !== get_post_type() )
        return $content;

    if ( 'au.example.com' === $_SERVER['HTTP_HOST'] )
        return "G'Day buddy!<br>$content";

    if ( 'uk.example.com' === $_SERVER['HTTP_HOST'] )
        return "How do you do?<br>$content";

    if ( 'us.example.com' === $_SERVER['HTTP_HOST'] )
        return "Hi!<br>$content";

    return $content;

You could also create metaboxes for the extra content, so the client can edit it. Then you check if there is extra content for this post with get_post_meta(), and if you found something, you change the content.

  • Thanks very much! Just so I'm understanding it right, 'page' will be the name of the page where I want the content yes? And then I could put this function in a header? Sorry, I still not to certain with the internals of wordpress. Apr 18, 2013 at 9:31
  • page is the post type. To get the full page object use get_post(get_the_ID()).
    – fuxia
    Apr 18, 2013 at 9:34
  • @boundless08 See my update for a more user friendly option.
    – fuxia
    Apr 18, 2013 at 9:46

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.