Forums

How to not show in top menu & only in custom menu (3 posts)

  1. tefnut
    Member
    Posted 1 year ago #

    Hi

    Im using the sandbox to make my custom theme and website.

    I have a menu across the top with links to all of the pages, but I have 3 links in there that I want to show on the left side bar as opposed to the top navigation, I've managed to put the 3 links in the left side bar using a custom menu. But now I want to stop these links from appearing in the top navigation, is there a way to do this?

    Thanks

  2. MichaelH
    Volunteer
    Posted 1 year ago #

    If those Page links are presented with template tag, wp_list_pages(), then look at using the exclude= argument.

  3. uGoMobi
    Member
    Posted 1 year ago #

    I know this is an old post, but nevertheless my code might be useful for someone.

    If you don't want to manually add or remove page-ID's to or from the exclude argument each time you edit your custom menu, you can add this function to your theme function.php file.
    The pages which you included in your custom menu ('name_of_your_custom_menu') will be excluded from the default wp_page_menu.

    function my_page_menu_args( $args ) {
    		$array = wp_get_nav_menu_items('name_of_your_custom_menu');
    		$list = array();
        		foreach($array as $key => $value) {
    				$menuitem = get_object_vars($value);
    				$list[] = $menuitem["object_id"];
    				}
    		$exclude = implode(",",$list);
    	$args['exclude'] = $exclude;
    	return $args;
    }
    add_filter( 'wp_page_menu_args', 'my_page_menu_args' );

Topic Closed

This topic has been closed to new replies.

About this Topic