No problem. You can insert the code in your functions.php of your theme.
Hi, I am also trying to put the switcher in the menu. I copied the code “as is” (except that I changed the menu name) in the functions.php file of my theme but absolutely nothing happens. Did I need to change, add, remove anything from the code? (I don’t know PHP so can hardly figure it out just with the instructions given). Is there something I can do to check why it’s not “acting on” the function?
I am pretty sure that the plugins’s settings are all ok since the widget works if I activate it. Thank you!
This is the solution if you want the switcher integrated in your WordPress menu. But there are other ways to create a similar output. Can you give me an example? Is there already a site where I can see something?
Thank you for your quick reply.
This is the site I am trying to put the language switcher on : http://www.prestigeexperts.com/fr/ . I have searched in the source code to see if anything was there but was not showing in the page, but there is nothing. I am using a bought theme, maybe there is something conflicting?
I have activated the widget feature in the footer so you can see that this part is working properly.
Ideally I would like to have the description link (no flag) in the secondary menu on the left (beside “Accueil | Contact”).
The name of the menu seems to be “top_menu”, isn’t it?
Yes, it seems like it… I have tried “top” and “top_menu” instead of “primary” in the code, but it doesn’t make it work. It is currently set as “top_menu”.
Could you check in your functions.php if the id of the menu is really top_menu? There must be at least one call to the function wp_nav_menu.
Haa! thank you so much 🙂 Turns out the only call to wp_nav_menu was in the header.php. I was able to see there that the menu id was really top_menu, but it’s “theme location” was top-menu… Thank you again!!
Hi,
I’d like to place the flags into the menu on my site too.
I’ve copied the code from here into my functions.php file but nothing happens.
I’m running twentytwelve here – Photoed.
Can you help at all please?
I use Twenty Twelve on my test-installation. Could you please check if your menu-function is similar to my function my_custom_menu_item.
Hi,
Thanks for the swift reply.
The menu function in my functions.php is
// This theme uses wp_nav_menu() in one location.
register_nav_menu( 'primary', __( 'Primary Menu', 'twentytwelve' ) );
Apologies if this is not the correct information. I am not particularly knowledgeable about code.
OK, so you could insert this code in your functions.php (I hope you are using a Child Theme):
function my_custom_menu_item( $items, $args ) {
if (
class_exists( 'MslsOutput' ) &&
'primary' == $args->theme_location
) {
$obj = new MslsOutput;
$arr = $obj->get( 2 );
if ( !empty( $arr ) ) {
$items .= '<li>' . implode( '</li><li>', $arr ) . '</li>';
}
}
return $items;
}
add_filter( 'wp_nav_menu_items', 'my_custom_menu_item', 10, 2 );
Cheers!
I have copied that code into the functions.php of my (newly created, thanks) child theme but it doesn’t seem to have any effect on the menu.
I have the plugin working perfectly from the sidebar widget so I know it’s not a fault with the plugin generally.
I would like for it to show in the menu too since I prefer not to have the sidebar activated on the front page.
Thanks again for your assistance.
Edward
In fact, don’t worry.
I will change my site to have the sidebar on the front page too.
It would be the simplest solution I think.