Check if current page has subpage


/ Published in: PHP
Save to your folder(s)

You may want to create navigation where the children are displayed only when the parent page is the current page. Place the code in your functions.php file


Copy this code and paste it in your HTML
  1. function hasChildpage() {
  2. $page = wp_list_pages('depth=1&child_of=' . $post->ID . '&echo=0');
  3.  
  4. if($page) {
  5. return true;
  6. } else {
  7. return false;
  8. }
  9. }

URL: http://awesomewordpressthemes.net/wordpress-tips/check-current-page-subpage/

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.