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
- Side bar only if it’s not a single post or a specific page
- WooCommerce: Custom dropdown for variation selection
- How to check if a plugin (WooCommerce) is active?
- How to use wp_insert_user on WordPress Multisite?
- Successful or Error Message after running mysql code in functions.php
- Trying to make php run in a post
- WordPress Site Running Extremely Slow on Dedicated Server
- Redirect undesirable domain
- Trying to install wordpress locally with mamp, but have unsupported php version
- Incorrect amount of posts returned when filtering related Woo products by custom taxonomy
- Theme’s Options Page included with require_once *.php in functions.php not visible anymore
- how to display this functions?
- How to have different site identity logos on each page on Astra Theme [closed]
- Set default Database Storage Engine when creating tables with plugins?
- How to tag the main tag? [closed]
- Overide Variable in Child Theme
- Randomize Color Scheme Selection in Theme
- Why can’t I add a custom image in my navigation?
- Calling a plugin from a page template in TwentyEleven
- Hi need update in my terms for other taxonomy
- I am having issue in divi woocomerce checkout module. (DIVI theme)
- display condition based on post term and status
- Not able to remove caption shortcode from the content
- Display WordPress archive template page in 3 columns and not 1 column [closed]
- How to get all post status
- How to change order inside foreach using wp_enqueue_script?
- The link you followed has expired. Please try again
- New database entry to trigger runing PHP/SQL query through link with token, without logging into the website
- How to get all users by user_login as a json_encode array?
- defined (‘ABSPATH’) false after AJAX post to other PHP-file
- Subheader title depends on post – change to static
- Use jQuery and AJAX to get HTML
- Loading a post’s content, into a div outside the loop, when it’s title is selected in a list
- Adding a Sub Menu Options Page WP Backend Menu. Whats wrong with my code?
- how to add display_name