• Resolved Garet H.

    (@pagetopixel)


    Great plugin! However is there a way to show a menu item on parent and subpages? It seem like you should be able to do this

    
    
    add_filter( 'if_menu_conditions', 'my_new_menu_condition' );
    
    function my_new_menu_condition( $conditions ) {
      global $post;
      $conditions[] = array(
        'name'    =>  'Condition Name', // name of the condition
        'condition' =>  function($item) {          // callback - must return TRUE or FALSE
    	  return is_page('Parent Page' ) || is_page('Parent Page' ) && $post->post_parent > 0;
        }
      );
    
      return $conditions;
    }
    
    

    But doesn’t seem to work.

    Thanks

    • This topic was modified 7 years, 11 months ago by Garet H..
Viewing 1 replies (of 1 total)
  • Thread Starter Garet H.

    (@pagetopixel)

    For anyone else that comes across this. Here is what worked for me.

    Add this to your functions.php

    add_filter( 'if_menu_conditions', 'my_new_menu_condition' );
    
    function my_new_menu_condition( $conditions ) {
      $conditions[] = array(
        'name'    =>  'insertpagename', // name of the condition
        'condition' =>  function(){
            global $post;
            $pages = get_pages(); 
            $post_parent = get_post($post->post_parent);
            foreach ( $pages as $page ) {
                if ( is_page('insertpagename') || $post_parent->post_name == 'insertpagename' ) { 
                    return is_page();
                }
            }
          }
      );
    
      $conditions[] = array(
            'name'    =>  'insertpagename2', // name of the condition
            'condition' =>  function(){
                global $post;
                $pages = get_pages(); 
                $post_parent = get_post($post->post_parent);
                foreach ( $pages as $page ) {
                    if ( is_page('insertpagename2') || $post_parent->post_name == 'insertpagename2' ) { 
                        return is_page();
                    }
                }
              }
      );
      return $conditions;
    • This reply was modified 7 years, 11 months ago by Garet H..
    • This reply was modified 7 years, 11 months ago by Garet H..
Viewing 1 replies (of 1 total)
  • The topic ‘Show if sub page’ is closed to new replies.