WordPress.org

Support

Support » How-To and Troubleshooting » [Resolved] Unique menu for one page and children pages.

[Resolved] Unique menu for one page and children pages.

  • I am currently using the below code to generate a secondary menu within the pages:
    page_parent_1
    page_child_1
    page_child_2

    Is it possible to set it up so that it will create the menu in the parent ‘page_parent_1’ and automatically add to all the children without adding every child page id or slug to the <?php … ?> code.

    <?php if ( is_page( array( 'page_parent_1', 'page_child_1', 'page_child_2' )) ) {echo wp_nav_menu( array( 'container_class' => 'menu-header', 'theme_location' => 'secondary' ) ) ;} ?>

    I have tried using && $post->post_parent & get_page_children but have had no luck.

    Any help is appreciated!

Viewing 2 replies - 1 through 2 (of 2 total)
  • I would use something like the following:

    <?php
    global $post;
    /* Replace "12" with the ID of page_parent_1 */
    if( 12 === $post->ID || 12 === $post->post_parent ) {
    /* Do your menu stuff here */
    }
    ?>

    Thank you very much. That works perfectly!

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘[Resolved] Unique menu for one page and children pages.’ is closed to new replies.
Skip to toolbar