Title: is_child function
Last modified: August 20, 2016

---

# is_child function

 *  [squill1959](https://wordpress.org/support/users/squill1959/)
 * (@squill1959)
 * [13 years, 2 months ago](https://wordpress.org/support/topic/is_child-function/)
 * Hi.
 * This plugin is exactly what I am looking for, but I am trying to understand the
   logic required for the visibility field.
 * I have added the following function to my functions.php file:
 * function is_child($pageID) {
    global $post; if( is_page() && ($post->post_parent
   ==$pageID) ) { return true; } else { return false; } }
 * and I am trying to use the following condition to display the menu item if the
   parent page is active or if a child of the parent page is active.
 * is_page(221) or is_child(221)
 * However it does not work, so if the function is correct, my logic is faulty.
 * Any suggestions would be appreciated.
 * [http://wordpress.org/extend/plugins/menu-items-visibility-control/](http://wordpress.org/extend/plugins/menu-items-visibility-control/)

Viewing 2 replies - 1 through 2 (of 2 total)

 *  Thread Starter [squill1959](https://wordpress.org/support/users/squill1959/)
 * (@squill1959)
 * [13 years, 2 months ago](https://wordpress.org/support/topic/is_child-function/#post-3476957)
 * Hi again.
 * The answer is I am wrong on two counts!
 * The is_child function doesn’t do what I expect and my logic syntax flawed.
 * Rather than ‘or’ it should be ‘||’.
 * In then end I used:
 * is_page(array(‘parent-page-name’,’peer-1-name’,’peer-2-name’))
 * which works, but is a bit unweildy as you have to manually add a new peer page
   to each menu item in a section.
 * What I am trying to achieve is to show the children of a menu item if either 
   the parent page is visible or any of the children of that parent page are visible.
   An is_peer(me) function.
 *  Plugin Author [shazdeh](https://wordpress.org/support/users/shazdeh/)
 * (@shazdeh)
 * [13 years, 2 months ago](https://wordpress.org/support/topic/is_child-function/#post-3477068)
 * Hi,
    if you have lots of menu items I would suggest to write a custom walker 
   for wp_nav_menu function.

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘is_child function’ is closed to new replies.

 * ![](https://s.w.org/plugins/geopattern-icon/menu-items-visibility-control.svg)
 * [Menu Item Visibility Control](https://wordpress.org/plugins/menu-items-visibility-control/)
 * [Support Threads](https://wordpress.org/support/plugin/menu-items-visibility-control/)
 * [Active Topics](https://wordpress.org/support/plugin/menu-items-visibility-control/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/menu-items-visibility-control/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/menu-items-visibility-control/reviews/)

 * 2 replies
 * 2 participants
 * Last reply from: [shazdeh](https://wordpress.org/support/users/shazdeh/)
 * Last activity: [13 years, 2 months ago](https://wordpress.org/support/topic/is_child-function/#post-3477068)
 * Status: not resolved