Support » Plugins » Exclude page(s) from navigation menu

  • This is for a child theme created from the default WordPress theme TwentyEleven.

    This is mean that you can exclude a page, group of pages or tree of pages without editing the main functions.php file while using a child theme.

    In your child theme folder create functions.php file and place in it

    function fcs_page_menu_args( $args ) {
    	$args = array(
    	'depth'        => 0,
    	'show_date'    => '',
    	'date_format'  => get_option('date_format'),
    	'child_of'     => 0,
    	'exclude'      => '',
    	'exclude_tree' => '',
    	'include'      => '',
    	'title_li'     => __('Pages'),
    	'echo'         => 1,
    	'authors'      => '',
    	'sort_column'  => 'menu_order, post_title',
    	'link_before'  => '',
    	'link_after'   => '',
    	'walker' => '',
    	'show_home' => true);
    	return $args;
    add_filter( 'wp_page_menu_args', 'fcs_page_menu_args', 'twentyeleven_page_menu_args' );

    Note: the fcs is just what i called my menu, you can call it what you want.

    I’ve used the basic default set up that wordpress gives you for the options. To exclude a specific page just put in the page id between the single quotes next to ‘exclude’ – for example

    'exclude' => '73',

    This will remove the page with the id of 73.

    To remove a page along with its child pages, put the parent id in the ‘exclude_tree’ section – i.e

    'exclude_tree' => '73',

    Then in the add_filter part at the bottom, add in your own menu;

    add_filter( 'wp_page_menu_args', 'twentyeleven_page_menu_args' );

    add_filter( 'wp_page_menu_args', '<strong>fcs</strong>_page_menu_args', 'twentyeleven_page_menu_args' );

    This means that the changes you have made will stay with your child theme and not get overwritten when you update the twentyEleven theme.

    Hope this helps, sorry if its been done before! If you know an easier way post and let me know, I’m no expert I was just trying things to see if it worked and it did!! Thought i’d share to make it easier to find – Cheers!

    tested on my localhost

Viewing 1 replies (of 1 total)
  • I should say, this will remove the page from the navigation bar but it does not close the page down, its still open and can be accessed like any other regular page, either by a link or typing in the address.

    Useful for something like a privacy page, copyright page or error page if you need to redirect your 404.php

Viewing 1 replies (of 1 total)
  • The topic ‘Exclude page(s) from navigation menu’ is closed to new replies.