Your above function tests whether a page is a child page of some other page, not whether it has children.
You can test for children of the current page like so:
function has_children() {
global $post;
$children = get_pages( array( 'child_of' => $post->ID ) );
if( count( $children ) == 0 ) {
return false;
} else {
return true;
}
}
Further reading:
Related Posts:
- List of all theme customizer control types?
- Set the transport of the Customizer ‘header_image’ core setting to ‘postMessage’
- Create another “Display Site Title and Tagline” checkbox, “Header Text Color” setting and control
- Converting HTML Template to WordPress Theme
- Compare the old get_theme_mod($name) to the new get_theme_mod($name) return value
- How to obtain the current website URL in my theme?
- What exactly do this function declared into functions.php file of a WP theme?
- Is there a hack for using is_page() within the function.php file?
- Where can I find the declaration of `$_wp_theme_features`?
- A Customizer checkbox control that sets the setting to “” or to “blank” and show() or hide() a color control
- My customizer’s setting doesn’t set to the default and needed to click the control’s “Default” button before it’ll be set
- WordPress causing all code to be displayed on line 1. Receiving multiple errors after cleaning cookies and cache
- How to add button to top of theme customizer?
- Why have on every line
- Proper use of Output Buffer
- Include a external PHP file into a WordPress Custom Template
- Need help setting default setting value for radio button in theme customizer
- How to remove hardcoded characters from playlists?
- function_exists call in function.php
- Debugging an error: wp_enqueue_style was called incorrectly
- Dynamically change feature image in customiser
- Change comments form title on a page by page basis
- Hide a menu-item and its submenus and display a ‘Log in’ link if the user is logged out
- Setting up the child theme so as to enable right-to-left WordPress?
- Design view breaking on Pages
- delete an array element when its date expires
- Understanding WordPress child theme custom JS loading
- How can I loop into two different DIVS without repeating the DIVs
- Removing unnecessary wordpress files
- How to add default images into theme customizer image control?
- Remove css styles from specific page
- Is the regular ajax request method safe or I should use admin-ajax.php?
- Can I change a variable in a content part while calling it?
- How to make thumbnail image fit into a div where image dimentions are completely different?
- Why WordPress architecture is not pure object oriented and it don’t use MVC pattern? [closed]
- How to break down importing of feeds
- Custom Logo URL | Help me print the URL of the custom logo I inserted into my theme
- My Own layout in WooCommerce pages [closed]
- Differences when using the the_time and the_date functions
- PHP can I add line numbers to file_get_contents()
- Displaying theme options in css
- Set WordPress Default Template
- Customizer: Output default value in Customizer CSS
- How to remove the cufon script from Dzonia Lite theme [closed]
- How do I add custom bulk actions to multiple custom post types?
- How to check if a meta value has already been assigned to any user?
- what is the best practice to add new field to an api route
- How to pick the default selected value in wordpress dropdown?
- Error in custom php function doesn’t exist
- Customizer: active_callback and sanitize_callback incompatibility?
- Populate editor with some content of a page with a page template
- Skt full width basic slideshow problem
- How to disable controls in theme customizer?
- Is the “_s” on this `sprintf(__(‘Page %s’, ‘_s’), max($paged, $page))` just refer to a text domain?
- WordPress admin-ajax.php
- Use WordPress function in php file
- How to call multiple functions from multiple files into a WordPress page template [closed]
- What file have I to create in my custom WordPress theme to show all the post belonging to a specific category?
- Theme not calling Jquery properly
- What is the best way to define constant options for a theme?
- Create page template via functions.php?
- List post by title length
- Removing “Powered by” footer using child theme PHP [closed]
- How do i wrap woocomerce attribute in list?
- get_theme_mod outputs number when using WP_Customize_Cropped_Image_Control
- How to add aria role and schema markup to custom walker container
- get_page_templates only return templates with “home” in the filename
- Extract and display user infromation on an automatically created page
- Show different website layout if no sidebar added
- How can I assign separate stylesheets to different pages?
- Need advice on theme customizer and child themes
- How to make sure relative URL works when site is not on root domain?
- pass html code to worpdress
- Customize field names in backend profile edit page through function.php [duplicate]
- WP insert post Redirect after function has executed
- Getting text from custom field from customizer
- Dynamically switch file in get_template_directory_uri() | Function [closed]
- WP-Bakery – Add custom colors to buttons with template colors
- Uncaught TypeError: extract(): Argument #1 ($array) must be of type array, null given
- How to change basename url for wp-admin?
- Trying to update Woocommerce meta values
- require get_template_directory() . ‘path/to-my/file.php’ BREAKS customize > themes functionality
- update_user_meta as multiple value but with same meta key
- Having trouble creating two shortcodes, one for logged in user and one for visitors
- Delete post meta by serialized meta value
- Remove node from multisites?
- Theme editing “post thumbnail” help
- How can I customize a WordPress theme before it’s downloaded?
- Calling PHP function doesn’t work in index.php
- How do I routinely extract the thumbnail of the most recent post?
- Display tab title as ‘blog tagline | blog title’
- Save the outputted image into the Media Library, with a different filename and extension
- WordPress get_post_meta issue
- Check if values exists DB
- How can I clear the theme mod settings?
- Select area and checkbox data is not saving?
- I need a button to appear when not loged in and another when logged in, I need help fixing code PLEASE!
- Load slideshow.css file only if Slideshow is checked / on
- WP Custom tables query
- Add multiple HTML attributes to an Elementor button