Skip to content

Instantly share code, notes, and snippets.

@prosvitco
Last active October 23, 2023 14:22
Show Gist options
  • Select an option

  • Save prosvitco/bb3ca4d48a15ce5544729a173af67f75 to your computer and use it in GitHub Desktop.

Select an option

Save prosvitco/bb3ca4d48a15ce5544729a173af67f75 to your computer and use it in GitHub Desktop.
Parent Page and Sub Pages Conditional Content Display
global $post;
if (is_page()) {
if ($post->post_parent) {
echo '<h1>Child page: ' . $post->post_title . '</h1>';
echo '<p>You can display content specific to child pages here.</p>';
} else {
echo '<h1>Page parent: ' . $post->post_title . '</h1>';
echo '<p>You can display content specific to parent pages here.</p>';
}
} else {
echo '<p>You can handle other content types or scenarios here.</p>';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment