Tagged: x
-
AuthorPosts
-
November 11, 2016 at 9:46 am #1253417
URL: http://dev.smarternetworker.com/
Latest version of X, Cornerstone & WPI want a specific menu named “Main Menu” to appear on my normal blog posts, archive pages and the home page.
I added the following code (slightly modified) that I found in this thread: https://community.theme.co/forums/topic/custom-menus-on-different-pages/page/3/
// ============================================================================= // Sets Custom Menu For Non-Member Pages // ============================================================================= add_filter( 'wp_nav_menu_args', 'menu_switcher' ); function menu_switcher( $args ) { if ( is_singular( 'post' ) || is_archive() || is_home() ) { $args['theme_location'] = 'primary'; $args['menu'] = 'Main Menu'; } return $args; }
The name I used (Main Menu) is taken directly from the “Menu Name” field: http://prntscr.com/d5zoql
Theoretically, my home page should now show a menu that has About, Products, Blog, Events, Contact, Login. However, it still shows my member’s menu which is just Login & Contact.
Can anyone tell me why it may not be working?
November 11, 2016 at 3:59 pm #1253788Hi there,
Would you mind providing us with login credentials so we can take a closer look? To do this, you can make a post with the following info:
– Link to your site
– WordPress Admin username / passwordDon’t forget to select Set as private reply. This ensures your information is only visible to our staff.
November 14, 2016 at 2:58 am #1256047This reply has been marked as private.November 14, 2016 at 3:37 am #1256099Hello There,
Thanks for providing the information. Please take note that is_home will only points to the blog home page. You must update your code and use this instead:
function menu_switcher( $args ) { if ( is_singular( 'post' ) || is_archive() || is_front_page() ) { $args['theme_location'] = 'primary'; $args['menu'] = 'Main Menu'; } return $args; }
Please let us know if this works out for you.
November 14, 2016 at 3:41 am #1256102Thanks Rue Nel! Works like a charm now.
November 14, 2016 at 4:30 am #1256154You’re welcome.
November 14, 2016 at 4:50 am #1256184Hey guys, just ran into one problem with this. I wanted it to only affect the primary nav (top of screenshot) and not any other menus like the icon menu I use further down the page (an Ubermenu found on some pages) http://prntscr.com/d72kik.
How would I exclude the filter from affecting anything besides the primary nav position?
November 14, 2016 at 6:53 am #1256323Hi Kenrick,
You can specify what menu you like for your footer.
Create file _nav-footer.php in wp-content/themes/x-child/framework/views/global
Then copy the code below into that file.<?php // ============================================================================= // VIEWS/GLOBAL/_NAV-FOOTER.PHP // ----------------------------------------------------------------------------- // Outputs the footer nav. // ============================================================================= ?> <?php if ( has_nav_menu( 'footer' ) ) : wp_nav_menu( array( 'theme_location' => 'footer', 'menu' => 'Footer', 'container' => false, 'menu_class' => 'x-nav', 'depth' => 1 ) ); else : echo '<ul class="x-nav"><li><a href="' . home_url( '/' ) . 'wp-admin/nav-menus.php">Assign a Menu</a></li></ul>'; endif; ?>
Hope that helps
November 14, 2016 at 8:23 am #1256412Hello Paul. I think you have misunderstood what I’m trying to do. I don’t need to put any menus in the footer.
Please read the first post.
The issue that I’m facing at the moment is that the code given by Themeco in post #1256099 works, but it tries to replace the primary navigation menu AND the menu in the middle of the page instead of just replacing the top menu (http://prntscr.com/d72kik).
How would I make the code from post #1256099 ignore all of the other menus on a page besides the primary nav position (top menu)?
November 14, 2016 at 10:03 am #1256585HI Kenrick,
Please update the cdoe Rue suggested to:
function menu_switcher( $args ) { if ( is_singular( 'post' ) || is_archive() || is_front_page() ) { if( 'primary' == $args['theme_location'] ) $args['menu'] = 'Main Menu'; } return $args; }
Hope this helps.
November 14, 2016 at 10:08 am #1256596Thanks Jade. That seems to have done what I need. How would I update the code if I need to add specific pages/post IDs?
November 14, 2016 at 10:09 am #1256598And what about specific categories/tags?
November 14, 2016 at 10:47 am #1256652Hi There,
Please try with this code:
function menu_switcher( $args ) { if ( is_single( array(123, 456) ) || is_page( array(567, 789) ) || is_tag( array('tag1', 'tag2') ) || is_category( array('cat1', 'cat2') ) || is_archive() || is_front_page() ) { if( 'primary' == $args['theme_location'] ) $args['menu'] = 'Main Menu'; } return $args; }
Hope it helps 🙂
-
AuthorPosts