Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Instead of using sidebar widgets to tell on what page they should be visible, I like to choose at the menu settings to appear on specific pages.

Default Wordpress way:

How it looks default

So projects is a page and has some subpages. But what if I have like 10 more of these pages and subpages with the same situation.

I would like to add an extra setting (a list of the top level pages):

Where I want the setting

But I cannot find any documentation, actions, filters etc when these settings are loaded.

share|improve this question
    
I think it depends on your theme. But as a starting point codex.wordpress.org/Navigation_Menus should help!! –  sri Jun 20 at 8:00
1  
I seen that link a lot of times, there is no information about adding settings to a menu. Only create and display a custom menu... –  Bondye Jun 20 at 8:01
    
Ouch. I think that is a native Joomla option, apparently not in WordPress. For your site, you could create custom output category/pages.php files and then add a unique custom menu there but that is a total pain in the neck. You'd have four output .php pages and four unique menus, one for each selection above. One easy way to implement is to use sidebar widgets as your primary navigation tool. the custom menu widget tool is pretty simple. Create a menu for each page, assuming you have unique templates for each. Note, sidebar is not the best word. You can put a widget anywhere. –  zipzit Jun 20 at 8:10
    
I am aware of the sidebars and widgets. These small website parts that are also not connected to a page. I don't want to use sidebars and widgets and have disabled them because I don't use any of them. Anyway, I think the menu locations are settings of the menu, not a setting of a widget which contains a menu. –  Bondye Jun 20 at 8:23
    
Is your question just "How do I add custom menu settings?" or is it also "How do I use custom menu settings to display a menu on certain pages only?"? –  engelen Jun 20 at 12:47

5 Answers 5

That's a nice option, but I agree with sri, right now it really depends on your theme. You can do a work-around through is_page(). You need to write something like this on your page.php theme file:

<?php
    if (is_page('projects')) {
        if ( is_active_sidebar( 'sidebar-navigation' )) {
            dynamic_sidebar( 'sidebar-navigation' );
        }
    }
?>

If you want to show the sidebar on other pages as well, you can use logic or like this:

if (is_page('projects') || is_page('home') || is_page('post-page'))
share|improve this answer

If you are willing to re-engage your widgets and want a simple solution, you can use a plugin called Display Widgets. I have used this and use the text portion where you can add links to where you want to go. It works whether the links are on you own site or to another site. It has a space down below the text where you can choose which pages to show or hide. You can still remove the widgets that you do not use.

I played around with the menus for quite a while before I looked for and found this plugin. It works well.

You can find it in the Plugins section of WordPress.org.

share|improve this answer
    
Thank you very much! But I am not looking for an extra plugin. And I don't use widgets since these floating website parts are too hard to understand for some of my customers. –  Bondye Jun 20 at 14:19

I think using a plugin for this is better, so you can keep the functionality even if you change themes in the future. Check out this plugin. It does what you want, but slightly differently than how you mocked it up.

https://wordpress.org/plugins/page-specific-menu-items/

If this helps, please up vote or accept as the answer. Thanks!

share|improve this answer
    
I have tried this plugin. With this plugin, you can only select a menu for a specific post type. I want to select the menu for each page. –  Bondye Jul 15 at 6:33
    
If you only have one menu across the site, and you just want to hide certain links in that menu when a user is on a certain page, this plugin does that. After you select the post type you want the menu on (page is what you want, or more) then go to edit a page, and you can check the links you want hidden. This other one does it the opposite way. You select a menu from a metabox on the edit page screen, so you need multiple menus to choose from: wordpress.org/plugins/ce-wp-menu-per-page –  Mark.C Jul 15 at 19:46

One option would be to make custom templates for each menu that you have. (That refers to the theme locations check box) Then on every page, you choose the template that you want it to use and it will also use the menu associated with that template.

https://codex.wordpress.org/Page_Templates

It gives you the same result I think you are looking for but rather than telling each menu what page it shows on, you will be telling each page what menu will show on it. An added benefit of doing it this way is that there is no way for you to accidentally tell two menus to be in the same place at the same time.

share|improve this answer
    
Yes, I have looked at this. But the developer never knows how many menus the user needs. So I have to create a lot of templates to cover them all. template_a.php, template_b.php, template_c.php etc. –  Bondye Jul 24 at 6:45

This is how you can do it in Twenty Twelve themes header.php copied to a child theme.

<?php if ( is_page('projects') ) : ?>
<?php wp_nav_menu( array( 'theme_location' => 'primary', 'menu' => 'conditional-menu-name', 'menu_class' => 'nav-menu' ) ); ?>
<?php else : ?>
<?php wp_nav_menu( array( 'theme_location' => 'primary', 'menu' => 'Primary', 'menu_class' => 'nav-menu' ) ); ?>
<?php endif; ?>

Create a new menu with the items you want to display and swap out the conditional-menu-name in the above code with the name of your menu.

menu_class names may need changing for themes other than Twenty Twelve.

Source

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.