Community Forums › Forums › Archived Forums › Design Tips and Tricks › Adding language switcher to main nav
Tagged: navigation
- This topic has 15 replies, 3 voices, and was last updated 10 years, 3 months ago by
lucaslem.
-
AuthorPosts
-
August 22, 2013 at 7:37 pm #58338
lucaslem
MemberHello, I am using the Multisite Language Switcher to link two different language sites (multisite install). I would like to add the switcher widget (essentially just a link) inside the primary navigation, so that it might sit along-side my other menu items. Just to be clear, I don;t just want it in the same widget area (currently header right) I would like to incorporate it into menu-primary-navigation.
Someone had a suggestion for a thesis theme here. Looking for similar solution.
Many Thanks
August 23, 2013 at 4:52 pm #58533David Chu
ParticipantHi,
I searched for quite awhile to find a way to do something like that. I even followed Bill Erickson's very fancy tutorial about some sort of fancy menu mod. I couldn't get what I was looking for.Instead, I figured out a way to do it using a more stock WordPress solution. I filtered the Primary menu, adding some code to it, and just did nothing if it wasn't the Primary menu. As you can see, I put my HTML block just before the menu. It could go after it, too. So this procedure should give you an idea of how it could be done with your multilanguage thingie. You may need to get your hands a little dirty with PHP, and use your plugin's directions for placing the switcher into your theme code.
// add block of text to menu add_filter('wp_nav_menu', 'dc_add_nav_text', 10, 2); function dc_add_nav_text ( $menu, $args ) { $args = (array)$args; if ( 'primary' !== $args['theme_location'] ) { return $menu; } $text = '<div id="navExtra">Creative ways to grow your business</div>'; return $text . $menu; }
Good luck, Dave
Dave Chu 路 Custom WordPress Developer – likes collaborating with Designers
August 24, 2013 at 12:52 pm #58611lucaslem
MemberHi Dave,
Pretty new to backend dev (PHP) so it's all slow going and not always clear to me where I can use genesis-specific code and where I need to incorporate general wordpress code.
I can across this link which includes some of your code. I'll poke around all of this and give feedback as to the failure or success in what I am trying to achieve.
In the mean time if anyone else has a Genesis-specific approach to this, I'm all ears.
August 26, 2013 at 6:57 am #58848David Chu
ParticipantLucas,
Sounds like a plan. I tend to look for Genesis solutions, too, because its hooks and filters are so handy, and generally require a small amount of code to get working. In some cases, the Genesis code becomes like shorthand - for instance, there's Genesis code for making new widgets, but the stock WordPress code for that is not too much bigger. I think you could define some Genesis functions as convenient wrappers for WordPress ones, while others are delightfully unique.The menu area is a little tricky, because it is a complex part of the system. If I remember, the Bill Erickson code I looked at was for modifying each menu item rather than adding a chunk of code next to it, so to speak.
I actually answered someone on Twitter one time who was looking to do something like what you are asking. She never responded, so I have no idea how far she got. I'll look forward to seeing what you come up with.
This is a fairly advanced topic, so it does require some careful study. If and when you get some code working, some CSS work will be needed to make it all look good. I say this because I see Genesis newbies trying similar things without getting help, and frankly, they will have a tough time.
One last thought... there is code in Genesis called Primary Navigation Additions. This adds various items to the menu, and examining that code could give ideas for this sort of thing, too. Doing that requires heavy geekiness, of course. 馃檪
Dave
Dave Chu 路 Custom WordPress Developer – likes collaborating with Designers
August 26, 2013 at 2:31 pm #58908lucaslem
MemberOk, I see where my problem lies. I am misleading by referring to my "primary navigation" which, in the studiopress demo is the full-width nav (located after the genesis header) and for which your code works perfectly. However, in my case I wanted the primary nav to be aligned with the logo and so I chose to place it in the header right widget area (genesis_header_right). In other words, there is no
primary
fortheme_location
Will keep digging. Perhaps there is a better way for me to structure my nav using CSS rather than using the header widget area.August 26, 2013 at 3:08 pm #58912lucaslem
MemberOr (even better) is there a way of targeting the nav in the header-right widget either by ID or theme location?
August 27, 2013 at 7:10 am #59034David Chu
ParticipantYou bet! For details, go here.
Adapting the code above, you can specify which menu, instead of which menu location. You'll get the idea, I'm sure.if ( 'Cool Lucas Side Menu' !== $args['menu'] ) { return $menu; }
Dave
Dave Chu 路 Custom WordPress Developer – likes collaborating with Designers
August 28, 2013 at 11:58 am #59259lucaslem
MemberHmmmm, I love this proposed solution to target by menu name rather than theme_location, but it doesn't seem to be working. The name of my navigation (from admin panel) is Primary Navigation. So here is the code changed accordingly (using your block of text example as a test):
// add block of text to menu add_filter('wp_nav_menu', 'dc_add_nav_text', 10, 2); function dc_add_nav_text ( $menu, $args ) { $args = (array)$args; if ( 'Primary Navigation' !== $args['menu'] ) { return $menu; } $text = '<div id="navExtra">Creative ways to grow your business</div>'; return $text . $menu; }
Something just isn't right...? Sorry for dragging this out, but I really can't figure out where the issue lies and google is not helping.
August 28, 2013 at 12:06 pm #59261lucaslem
MemberAaahhhhh, just saw my syntax error!
Needed to change
if ( 'Primary Navigation' !== $args['menu'] )
to
if ( 'Primary Navigation' == $args['menu'] )
Going crossed-eyed!
August 28, 2013 at 12:13 pm #59266lucaslem
MemberNope, that just adds it everywhere. Ugh.
August 28, 2013 at 12:22 pm #59270Sridhar Katakam
ParticipantAnother similar method (not that it is better, just stating options) is to create a sidebar (widgeted area) and stick this in the navigation. Then you can put any widget in this sidebar.
See this for an example: http://sridharkatakam.com/how-to-add-a-widgeted-area-in-navigation-bar-in-genesis/
August 28, 2013 at 12:24 pm #59273David Chu
ParticipantLook at your menus. Primary Navigation is a location, not a name of the menu. Look at the menu itself for the name. This is my final answer! 馃檪 The rest is up to you.
Good luck.
Dave Chu 路 Custom WordPress Developer – likes collaborating with Designers
August 28, 2013 at 12:31 pm #59274lucaslem
MemberDavid, Primary Navigation just happens to be what I called my main nav in the admin; in this case it is the name of the menu. I have also tried it with other menus registered on the site (one called "minor nav" etc). Still no dice. Thanks for your patience and final answer. Will keep searching.
Thanks Sridahr, will explore this avenue as well though at first glance it's not quite what I'm after.
August 28, 2013 at 2:35 pm #59315lucaslem
MemberFor anyone interested I got a solution to the issue (largely came from support from the language swithcer plugin developer):
wp_nav_menu_items
is a filter-hook. You should check what is in$items
and$args
. Why not just check the name of the handle?
Read on here: http://wordpress.stackexchange.com/questions/2143/customizing-only-a-specific-menu-using-the-wp-nav-menu-items-hookThis does not explain to me why the last code block I posted here does not work, but it did fix my issue.
August 28, 2013 at 2:41 pm #59316David Chu
ParticipantHi,
One last clarifying point: in my first code example, the exclamation point means "NOT". So the code is organized like this, using pseudo-code:---------------------------------------------------
If the menu is NOT the "one I have in mind", get out, and just show the regular menu.If it is the "one I have in mind", stick some gunk right next to it, and then get out.
------------------------------------------------------It doesn't have to be organized like that. You could simply code it to look affirmatively for that menu, and when found, do something. Also, to get this type of thing, you'll probably need to read up on arrays and subscripting. 馃檪 I know that's not welcome news for everyone. Even though Genesis is absolutely killer, to make it do every last little thing, some PHP ability is mandatory, IMO.
Sridhar's idea is an interesting one. It allows more flexibility than my hard-coded method.
D
Dave Chu 路 Custom WordPress Developer – likes collaborating with Designers
August 28, 2013 at 2:57 pm #59323lucaslem
MemberIt doesn’t have to be organized like that. You could simply code it to look affirmatively for that menu, and when found, do something.
Given that I have several menus, that was exactly the approach I was trying with
if ( 'Primary Navigation' == $args['menu'] ) { return $menu; }
Where "Primary navigation" is not the theme_location but the menu name. This is the part I am still dumbfounded by. It's as if using the $menu parameter rather than the $theme_location parameter just didn't work.
And yes I wholeheartedly agree regarding the PHP abilities. I am doing the tutorials, reading the books, and being a good student. But also the best way to learn is to do and take things apart in order to understand. Thanks for all your feedback as you have contributed to that process.
-
AuthorPosts
- The forum ‘Design Tips and Tricks’ is closed to new topics and replies.