How to redirect a Parent Page to a Child Page in WordPress

Q: How do I redirect a parent page to the first subpage in my WordPress navigation?

A: I have had to do this many times on sites with deep content, especially with drop down menus. It’s so easy for a visitor to a site to go directly to the first page in the drop-down menu and completely miss looking at what might be the most important information on the main parent page.

There are a couple different ways to approach this, and many websites and plugins do a 301 redirect which redirects the page to a page of your choosing. However, 301 redirects are typically used for redirects that are meant to be permanent — such as a page on the site that doesn’t exist any more and over time should stop getting hits. These redirects show up in your stats much like 404 page not found stats.

A clean way to deal with parent to first child redirects is to simply set up a page template with the following code and then choose this template as the template for the parent page.

Creating a Custom Page Template to Redirect a WordPress Parent Page to First Child Page

To do this:

1 – Create a new, blank php file in a text editor. Call this file page-gotochild.php.

2 – Copy the following code into the file.

Template Name: Go to first child
$pagekids = get_pages("child_of=".$post->ID."&sort_column=menu_order");
if ($pagekids) {
$firstchild = $pagekids[0];
} else {
// Do whatever templating you want as a fall-back.

3 – Save the file and upload to your active theme’s folder (in the wp-content > themes > nameofyourtheme folder).

4 – Log in to your WordPress Dashboard.

5 – In your Pages list, hover over the parent page you wish to redirect to the first child.

6 – Click Quick Edit and choose Go to first child from the Template list.

Selecting page template in WordPress QuickEdit

7 – Click the Update button.

Now this page will automatically go to the first child page when you view the page. However, the first child may not be the page you want it to redirect to as the first child is the first child alphabetically.

Changing Order of WordPress Pages Using Order Number

Default Page Order – Alphabetical

To re-order your child pages,  you can use Quick Edit to assign each page an Order number. This can be tedious if you have a lot of child pages to order. To order a lot of child pages, the Simple Page Ordering Plugin rocks! It allows you to drag pages in your page list to the order you wish.

If you would like to avoid installing yet another plugin, you can manually reorder your pages as follows:

1 – In the Pages list, hover over the page you would like to be the first child page.

2 – Click Quick Edit.

3 – In the Quick Edit window, type 10 for the page order. (Note: I always use increments of 10 for page ordering in case I need to insert a new page between two pages later. This avoids having to renumber all of the pages.)


4 – Click the Update button.

5 – Repeat for all the child pages using increments of 10.

The new page order will look like this:

New page order with Services parent page redirecting to Our Services
New page order with Services parent page redirecting to Our Services

WordPress Page Order and Custom Menus

If you are using Custom Menus (Appearance > Menus), you can certain order the pages as they appear in the menu via the Custom Menu interface, however, this page “order” is not official — it is simply cosmetic for the purposes of displaying items in the menu. Therefore, if a page appears as the first “subpage” on the Custom Menu, it does not mean that it will display a the “first child” according to our little script above. You still need to set the page order in the list of Pages.

Angela Bowman

Front-end WordPress developer since 2007 building highly custom websites for nonprofits and small businesses. Experienced in nonprofit administration, grant writing, and technical writing. Love high altitude hiking and backyard chickens.

View all posts by Angela Bowman

41 comments on “How to redirect a Parent Page to a Child Page in WordPress

  1. Unfortunately, this has stopped working for me. I copied your code exactly, and the redirection still doesn’t work. Just brings up a blank page. The page is a parent, and definitely has children. Not sure what else it might be. Any thoughts? Maybe my host has some settings off?

    • Hi Adam. I tested this, and it works. However, the quotes in the code snippet turned to be “curly” instead of straight. You also don’t need the ending ?>. So if you fix the quotes and remove the ending ?>, it should work fine.

      My code snippet plugin stopped working, so it messed up the quotes. Sorry about that.

  2. Hi Angela
    Was working nicely until I installed WP5 and the latest Divi Theme.
    Any clue?
    I get this error message on my page now:
    Parse error: syntax error, unexpected ‘$pagekids’ (T_VARIABLE) in /var/www/vhosts/ on line 7

    • I can imagine that happening on a page if it doesn’t have any child pages. So make sure the page you are using this on is a REAL parent page and has real children in the Pages > All Pages list and not just in the menu navigation. Also, make sure the page template coding is correct and that there aren’t any curly quotes in the code. All the quotes should be straight quotes. Let me know what you find!

    • This doesn’t use a plugin. It’s a page template, and then can be used on any page on the site. It’s nice because people can apply it as desired and not have to understand how to write the redirect in .htaccess.

      However, what I have been doing for SEO is always having a top level page as a clear navigational structure of top level and second level pages is good for Google especially when it comes to the site navigation on the Search Engine Results Page. I make sure to include the top level page in the drop down menu in case some people are more included to click an item in the drop down than the top level.

      What do you think is best for SEO as far as navigation goes?

  3. [* Shield plugin marked this comment as “0”. Reason: Human SPAM filter found “” in “author_email” *]
    What a clever idea, setting up a template like that. Very easy to implement too.

    Thank you – will be trying it out tomorrow!

    • Hi Tigran,

      Yes this method relies on using a page template, so you can choose it on any page of the site, and it will automatically redirect that parent page to the child page.

      I’m not sure what code you are using for your redirection, so I can’t tell you what might not be working with that. page.php is used for all pages on the site, so that’s why it helps to make a template for this.


  4. Hi,
    We are converting our site to WordPress and we are working on a beta version to make changes before we go live.

    I have this issue on two Parent pages on our site. One page is a list of press releases. I tried adding numbers to the Order field in the Page Attributes section of the child page but it doesn’t change the order. Every time I add a page and select the parent page it adds it to the bottom of the list of press releases.

    Another page is a list of Articles. Same issue, when I create a new article, it just adds it to the bottom of the list of articles on the parent page.

    I see there are some plugins for reordering posts, but I was not sure if I’m missing something before we try a plugin.

    • Hi Mary,

      For Press Releases and Articles, I recommend using posts instead of pages as pages will get out of control super quick, and you’ll have hundreds of pages in no time which because quite unwieldy to manage. Posts are the best type to use for content that continues to grow. Pages are static, but may create dynamic content, like a list of posts.

      So, I would have your two pages: Press Releases and Articles, BUT don’t create child pages off of these. Instead, create POSTS and put them in a categories called Press Releases and Articles (use a different slug than the Press Releases page). Then using PHP code or a plugin, you can pull these posts onto their respective pages.

      By default, posts are ordered by entry date, so you can use whatever plugin or PHP you are using to populate the page to change the orderby criteria or use the plugin to manually order the posts or set the defaults.

      Let me know if you have any questions.


    • Yes, I do that, too. It’s a great solution! Often, I’ll make that parent page not have any super important content in case people don’t click on it and make it sort of a landing page with navigation to the child pages. Thanks for mentioning that.

  5. Having trouble getting this to work when visiting my site on a smartphone. The redirect doesn’t work, it just displays the blank page.

  6. This was great and super simple to implement. One question though…Everything works perfectly except on a mobile browser. When i try to navigate via top level item on my iPhone, I get an error saying line 5 of the .php has errors and am not navigated to the child. Has anyone else encountered this or know how to fix?

  7. Hi Angela,

    I’m a newbie when it comes to WordPress sites, and I’ve tried searching for an answer to my question … hence coming across your site 😀

    I have a client site that I have created a sub/child page and when I try to access the parent page, the site automatically skips to the sub/child page (I hope I’m explaining this properly).

    The site is and the “problem” page is Tips And Tricks.

    I’m assuming I’m missing something fairly obvious, but having looked at this for a couple of hours, I have no idea where to turn next … are you able to help please?

    Thank you


    • Hi Cathy,

      I edited your comment, so now you don’t have to apologize. 🙂

      I see a few things about your navigation to investigate:

      1 – The Home link goes to instead of so you might want to fix that.

      2 – The main nav is on the home page is set up to go to what is called anchor links on the page, so when you click on the link, it takes you to spot further down the page. Under Appearance > Menus, you will probably see this.

      3 – The Tips and Tricks page itself seems to come up okay: on its own.

      So, if you don’t want to use the crazy anchor link stuff in the menu, then you might want to modify the menu under Appearance > Menus to actually contain links to the pages rather than links to the anchor tags.

  8. Hi guys, Think I found of another easier way to do this but you may know better why this isn’t right – I’m just learning…

    When you create a Menu in WordPress you can add a link as a Top Level Menu item and put in whatever link you like, so you can add in the link to the first child page there, even though the Link Title is called something else.

    • Yes, this is a good solution, and I do that often or simply use the # symbol for the link to force people to have to pic an item from the drop down menu. However, if Google indexes the page, visitors to the page will go to a blank page. So, you might want to delete the blank page or use the instructions in this post to redirect that page automatically to the first child page.

  9. Hello,

    Thank you so much for posting this. It will save me hours of research, this was on my to do list before I go live with my website.


    • Awesome, Linda. And great to see you on Twitter, too. I’m sorry for the late response. For some reason, I didn’t see all these comments. Anyway, I’m glad it helped.

Leave a Reply

Your email address will not be published. Required fields are marked *