WordPress.org

Ready to get started?Download WordPress

Forums

TwentyTwelve: Add page that does not appear in the top menu (7 posts)

  1. jakobrosenkrantz
    Member
    Posted 1 year ago #

    I would like to add pages that do not appear as items in the top menu in the TwentyTwelve theme. Instead, I will link to these pages on other pages that appear in the top menu.

    I looked a bit around for a solution, and somewhere it was suggested that pages could be excluded via their IDs, using wp_list_pages() (see http://codex.wordpress.org/Function_Reference/wp_list_pages#Exclude_Pages_from_List ). However, I did not quite understand where this should be executed.

    So could someone please be explicit about how to exclude a specific page from appearing in the top menu?

  2. WPyogi
    Volunteer Moderator
    Posted 1 year ago #

    You can simply create the pages and remove them from the menu - see:

    http://codex.wordpress.org/Appearance_Menus_Screen

  3. leejosepho
    Member
    Posted 1 year ago #

    I do what you are asking about by making posts at the Dashboard and not having them display anywhere, then add the post's links wherever I want them on the pages in the menus.

  4. alchymyth
    The Sweeper & Moderator
    Posted 1 year ago #

    the best and easiest way is as @WPyogi suggested.

    if you want to customize the theme to exclude pages from the top menu,
    start by creating a child theme of Twenty Twelve; http://codex.wordpress.org/Child_Themes

    Twenty Twelve uses 'wp_page_menu()' as a fallback if the custom menu is not activated; this needs to be influenced in functions.php;

    add a new functions.php into the child theme's folder; make sure to have the <?php at the start;

    add this code (the numbers are the page IDs of the pages you want to exclude):

    function twentytwelvechild_page_menu_args( $args ) {
    		$args['exclude'] = '2,4,37';
    	return $args;
    }
    add_filter( 'wp_page_menu_args', 'twentytwelvechild_page_menu_args', 20 );

    http://codex.wordpress.org/Function_Reference/wp_page_menu

  5. jakobrosenkrantz
    Member
    Posted 1 year ago #

    You can simply create the pages and remove them from the menu - see:

    http://codex.wordpress.org/Appearance_Menus_Screen

    Thanks, this did the job; I created a custom menu and added the pages I want to appear in the menu. Excluding the page I did not want in the menu in this custom menu quite naturally did the job:-)

    the best and easiest way is as @WPyogi suggested.

    if you want to customize the theme to exclude pages from the top menu,
    start by creating a child theme of Twenty Twelve; http://codex.wordpress.org/Child_Themes

    Twenty Twelve uses 'wp_page_menu()' as a fallback if the custom menu is not activated; this needs to be influenced in functions.php;

    add a new functions.php into the child theme's folder; make sure to have the <?php at the start;

    add this code (the numbers are the page IDs of the pages you want to exclude)...

    I already made a child theme, so thanks also for this suggestion. Is this in any way a better way to exclude pages?

    As I see it, when all I want is to exclude one or more pages, the procedure described above is simpler. But if more changes, e.g. customization of the design of the menu, is needed the changes in functions.php are required. Is that correct?

  6. alchymyth
    The Sweeper & Moderator
    Posted 1 year ago #

    Is this in any way a better way to exclude pages?

    no - just different.

    as I already mentioned, working with the custom menu is the best option.

    But if more changes, e.g. customization of the design of the menu, is needed the changes in functions.php are required.

    no - once you work with the custom menu, you can ignore that particular bit in the functions.php.

  7. KevinLycett
    Member
    Posted 9 months ago #

    alchymth
    Thanks for that code it's exactly what I'm looking for but I'm confused.
    There are two bits of code in that php, the second starting with 'add_filter'. It ends with ...args', 20);
    Is the number 20 also a page number? If not what does it do?
    Thanks
    Kevin

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags