How to display specific content WordPress child pages

Let’s say you’re looking to display content on your WordPress pages but only for child pages of a specific section of your site. Here’s how to do it in just a couple of steps.

First, add the following code to your theme’s functions.php file:

function is_tree($pid) {
  global $post;
      return true; 
      return false;

Next, open your page.php theme template and add the following where you want the content on your child pages to display:

<?php  global $post; 
  if (is_tree('PARENT PAGE')) {

Change PARENT PAGE to the name of your parent page. For example, if your parent page is Resources, then enter ‘resources’. This ensures your content will display but only on subpages of

Replace YOUR CONTENT HERE with your content.

Push the changes in these files to your theme directory and try it out.

Archived under:
This site uses cookies to collect basic info to help improve your experience. Read my Privacy Policy Accept