How to use WordPress to host a single page on a subdomain

We have all been there, you have a client ask!

Can we put a page from our WordPress website on a subdomain?

If your like me your first thought was probably what about WordPress Multisite?  –

MultiSite can be great but there can be a lot of work involved to set it up and get it working on a subdomain. There are also other things to consider like having multiple admin dashboards for the different domains etc.

So is there another way you ask?

Well… I did some digging around and came up with a solution, it requires dropping some code into your themes functions.php file but its pretty simple to get working.

Here are the steps to get this to work:

  1. Point the subdomain that you want to use at the root of the website (I won’t go into that side of things here).
  2. Create the page that you want the subdomain to point at and make sure the page name matches the subdomain.
  3. Add the code below to your functions.php file
  4. Open the subdomain in your browser and watch the page display on that subdomain 🙂

 The Code:

Hat tip to the person who’s subdomain extraction function I used from StackOverflow here

You can see it in action here

I created a page called subdomain and it displays the demo page in place of the homepage. You can also see all the other links  work but ideally you don’t want to have whole site displaying as it could be seen as a duplicate site by google.

I hope you find this useful, any questions hit me up in the comments below.

For more tips and tricks be sure to sign up to my newsletter below.

  • This field is for validation purposes and should be left unchanged.


  1. Hai on January 9, 2016 at 9:00 am

    When i add your code in function.php and wordpress show syntax error unexpected ‘&’ in line if ( ! $query->is_main_query() || is_archive() || is_single()) {
    Can you help me fix this problem.
    Thank you.

    • ninjamonk on January 9, 2016 at 2:43 pm

      sure, there is no & in the code so check the line above.

      feel free to past in your function and I will take a look at it.

  2. Kingsley Muir on May 9, 2017 at 12:28 am

    Has this been “fixed” in a more recent update of WordPress?

    I’d love to be able to do this, but for some reason, when i point to the subdomain, it redirects to the blog’s home page, is there anything else I need to do to stop that?

Leave a Comment