I ended up using this code:
<?php
global $post;
$children = get_pages( array( 'child_of' => $post->ID ) );
if ( is_page() && $post->post_parent ) : ?>
This is a child-page.
<?php elseif ( is_page() && count( $children ) > 0 ) : ?>
This is a parent-page (with one or more children)
<?php else : ?>
This is a parent page without children.
<?php endif; ?>
Related Posts:
- Current post’s author name in the author meta tag
- Easy way to process search results before displaying
- Conditional statement for parent, child and grandchild pages
- Trying to use Ternary operators with WP Conditionals
- Get only the grandchildren, not the direct children of page/current page?
- When is is_admin() available?
- Check if current page is wp-admin
- Second Navigation inside header
- Using is_page() in functions.php not working at all
- Output 2 items within the Loop
- conditional statement for custom taxonomy
- How to enqueue CSS and JS only on specific template?
- How do I list the child of a child page [duplicate]
- how could I load a different template part by page
- How to hide all child pages with post_query?
- WordPress, AJAX and pre_get_posts using conditional tags
- Child page menu in sidebar
- How do I Turn This Into An if statement?
- Query Pages and post excerpts dynamically
- get_the_title() gets printed out twice
- If tag equals then show else show
- Conditional statement for dates
- How can I display a div ONLY if it is not a certain term page
- Don’t show certain div on front page?
- If ‘editor’ is empty, then
- Add class to DIV depending on page loaded
- How to: Conditionally Enqueue JS and Stylesheets, for Custom Post Type (Single and Archive Templates)
- WordPress child pages not working
- Undefined index for default custom theme option
- Remove conditional tag from header
- Display child page content of a specific parent on home page
- Display an image based on field value
- Multidimensional Array
- “if parent category is” conditional?
- Conditional for Post Format
- conditional: if is page, and all subpages
- Woocommerce getting top level category parent and make all sub categories have the same template and menu
- page 1 is not paged
- How to add Text before my Custom Term and hide it when empty
- How can i create a function tag in my plugin
- Add code to the header of posts by particular author
- Display specific page if user signed in
- Child and Parent Pages list of sub pages
- How to get Post sidebar & footer including html like get_the_content() which only gets content section?
- Getting a value from a custom field from a page that shares a parent with the current page
- Widget Logic – display on page and all child
- My function echos only “array”
- PHP: Why does my code work in index.php but not a widget?
- Need to adjust condition to say if I’m pulling categories from a post, to pull only the first one
- if user is admin display admin link and logout link else display logout only
- Add code only for blog posts
- List of child pages fetch next results at link click
- Sidebar current menu item for parent
- How to define Og Meta Tags in header using conditions [duplicate]
- If Month=Particular month display content [closed]
- How to echo a different field if another field is empty?
- Adding else if conditional statement to purchased theme
- Conditional in foreach loop is outputting content twice
- Advanced custom fields Repeater conditional statement not working [closed]
- Load slideshow.css file only if Slideshow is checked / on
- Issues trying to add a href statment with PHP into a PHP Echo Statement [closed]
- if is specific custom post in cpt
- advanced custom fields: repeater field within conditional statement [closed]
- WordPress Block Editor Gutenberg running code inside ! is_admin()
- How to make my scroll bar show under condition
- How to pull through page title depending on which radio button is selected on the specific page?
- Side bar only if it’s not a single post or a specific page
- WooCommerce: Custom dropdown for variation selection
- Need oop for wordpress theme? [duplicate]
- Display Youtube Time Automate from Key
- Content filter won’t work
- How to retrive the text : No movie by this actor
- Make a database query using WordPress
- Is the 404 page automatically displayed if a loop returns nothing?
- update_post_meta only updating on last loop of foreach
- How to have different header.php based on the user logged in?
- How do I remove a category from a wordpress loop>
- How can i count the post added in relationship field, theme display
- Link blogname and blogdescription to the Options Framework
- Liking a facebook page from wordpress website?
- Isotope Drop Down Categories Filter Function
- First Byte Time (back-end processing)
- How do I define a lookup table that will work across all PHP elements of the template?
- How to keep track of when a vote is cast?
- trouble with page_id & highlighting current page
- Convert the_permalink() function output into string
- Making my first wordpress template
- How to use array in function to get only value I want
- Apply class to every third list item? [duplicate]
- Only show image from custom field when present
- Cinema site, retrive the movies that actor play in
- How to include custom code on a page that’s set to act as homepage?
- retain querystring values when savincustom options in admin
- PHP if statement works in template files, but not header
- How Can I Edit the Registration Code?
- Error while setting role
- Editing a PHP file to include a small text piece on every page
- Get categories names as an array to use it in theme settings
- Should i use the wordpress Options table or to create database table..?
- variable value disappears in a second loop