Community Forums › Forums › Archived Forums › General Discussion › Add custom filter to a secondary nav
Tagged: wpml
- This topic has 10 replies, 3 voices, and was last updated 9 years, 5 months ago by Ebelanger.
-
AuthorPosts
-
May 11, 2015 at 8:43 am #151712EbelangerMember
Hello,
I'm trying to show the inactive language in my secondary nav menu with wpml.
So far I'm able to output correctly my custom inactive to my genesis header.
But it doesn't get outputed in my secondary nav menu.
Anyone can help me?
May 11, 2015 at 9:11 am #151721Johann KratzikMemberIn short, this task requires 2 steps:
- Creating a widget area to include into the menu
- Filtering wp_nav_menu_items to include this widget area into the navigation menu. Tutorial at http://www.wpbeginner.com/wp-themes/how-to-add-custom-items-to-specific-wordpress-menus
Let me know if this helps or if you need a working example.
Offering customization work for FREE – Read more
May 11, 2015 at 9:28 am #151725EbelangerMemberHello Johann,
Thank you very much for the information.
I'll look into it.
So far, I already have a secondary in the above_header hook. Do I need to create a new one for my custon filter?
Or the step one, you talk about is to create the space for the secondary menu at the beginning?
Thanks again for your time.
May 11, 2015 at 9:55 am #151726Johann KratzikMemberYou can keep the menu in this hook, the filter only changes the menu output and will add the widget area to the menu items.
Step 1 is to create an additional widget area. You can put the WPML language switcher into this widget area in the backend.
However there will be a third step, CSS tweaks. Probably you want the switcher floating to the right side, you want to hide the active language. And maybe adjust the look of the WPML widget.
Offering customization work for FREE – Read more
May 11, 2015 at 10:05 am #151727EbelangerMemberHi Johann,
I was able to move the menu in the secondary menu and the primary. I just 'display:none' on my primary menu for that item.
Now my question, I have is:
How can I change the order in which i want the language to show. Now it's showed at the beginning of my secondary menu. I would like to appear at the end.
I'm pretty sure it's just the order number to change but where?
Thanks again. You helped me a lot.
Yours,
May 11, 2015 at 10:14 am #151728Johann KratzikMemberIn the HTML source code search for the id in the
- item that holds the widget. Then make this item float: right in stlye.css
Offering customization work for FREE – Read more
May 11, 2015 at 1:23 pm #151757Johann KratzikMemberHere is the full example code. I have tested and it should work in all Genesis child themes:
//* Registering the widget area to display in the secondary navigation genesis_register_widget_area( array( 'id' => 'nav-widget', 'name' => 'Navigation widget', 'before_widget' => '<li class="menu-item wpml-nav">', 'after_widget' => '</li>' ) ); //* Filtering the secondary navigation to insert the widget area add_filter( 'wp_nav_menu_items', 'jk_menu_widget', 10, 2 ); function jk_menu_widget ( $items, $args ) { if ( $args->theme_location == 'secondary' && is_active_sidebar( 'nav-widget' ) ) { ob_start(); dynamic_sidebar( 'nav-widget' ); $nav_widget = ob_get_clean(); $items .= $nav_widget; } return $items; }
Offering customization work for FREE – Read more
May 11, 2015 at 1:47 pm #151764EbelangerMemberThank you very much Johann.
I give it a try.
So far, I'm good with what I have. I'll try later on to move it to the right side of my menu. At least it works perfectly.
Thank you very much for you time and knowledge.
May 11, 2015 at 2:16 pm #151774Johann KratzikMemberWelcome! If the solution works, please mark the thread as "resolved" so it can be closed. If you still need help post it here.
Offering customization work for FREE – Read more
May 11, 2015 at 2:48 pm #151777Brad DaltonParticipantThis is the code you can use
<script src="https://gist.github.com/braddalton/428545d1431fcaf8152b.js"></script>
May 12, 2015 at 6:51 am #151838EbelangerMemberThank you guys for your help!
-
AuthorPosts
- The topic ‘Add custom filter to a secondary nav’ is closed to new replies.