Jump to content

Archived

This topic is now archived and is closed to further replies.

ketri

What is the name of the mobile menu (to be used in functions.php)?

Recommended Posts

ketri

Hello

I want to add WPML language-code -links to my nav.

I have managed to use this code

 

function new_nav_menu_items309676($items,$args) {
    if (function_exists('icl_get_languages') && $args->theme_location == 'main_nav') {
        $languages = icl_get_languages('skip_missing=0');
        if(1 < count($languages)){
            foreach($languages as $l){
                if( $l['active'] != 1 ) { 
                    $items = $items.'<li class="menu-item-'.$l['language_code'].'"><a href="'. $l['url'].'">'. strtoupper( $l['language_code'] ).'</a></li>';
                }
            }
        }
    }
    return $items;
}


add_filter( 'wp_nav_menu_items', 'new_nav_menu_items309676',10,2 );

in my functions.php to add them to the main nav.

How can I add them to my secondary mobile nav also?

I tried to copy-paste the same code and replace the 

$args->theme_location == 'main_nav') {

with 

$args->theme_location == 'seconday') {

but had no success.

Thanks!

 

Share this post


Link to post
Share on other sites
James B

Hi there, looking in the core code it's listed as 'secondary_navigation_menu'

 

http://screencast.com/t/oaQIDvgzzi

 

That's listed in the file DMS > editor > mobile.menu.php


Kindly search the forum and read the documentation before posting. It will help you resolve many issues.

For CSS help be sure to check out W3Schools first and be sure to download FireBug for FireFox for troubleshooting.

James B

Share this post


Link to post
Share on other sites
ketri

Thank you James, 

Unfortunately the code I posted works ONLY with:

if (function_exists('icl_get_languages') && $args->theme_location == 'main_nav')

It doesn't work with 

if (function_exists('icl_get_languages') && $args->theme_location == 'secondary_navigation_menu')

or

if (function_exists('icl_get_languages') && $args->theme_location == 'primary_navigation_menu')

What's going on and how can I add items to specific menus using functions.php?

Thanks!

Share this post


Link to post
Share on other sites
James B

Hi there, unfortunately my php isn't strong enough to advise further there. Those are the only two areas I can see in the source code which relate to that those areas.

 

Simon_P might be able to advise. Simon, would that be the correct theme location to change the menus above?


Kindly search the forum and read the documentation before posting. It will help you resolve many issues.

For CSS help be sure to check out W3Schools first and be sure to download FireBug for FireFox for troubleshooting.

James B

Share this post


Link to post
Share on other sites
ketri

Hi there, unfortunately my php isn't strong enough to advise further there. Those are the only two areas I can see in the source code which relate to that those areas.

 

Simon_P might be able to advise. Simon, would that be the correct theme location to change the menus above?

Thanks. Let's see if we can find a solution.

Share this post


Link to post
Share on other sites
ketri

@Simon_P
Could you help me out with this one? 

1. DMS2

2 I'm using the Navbar section and have selected the menu

3.In my functions.php i have:

 // add shortened language codes to the footer  function new_nav_menu_items309676($items,$args) {
    if (function_exists('icl_get_languages') && $args->theme_location == 'main_nav') {
        $languages = icl_get_languages('skip_missing=0');
        if(1 < count($languages)){
            foreach($languages as $l){
                if( $l['active'] != 1 ) { 
                    $items = $items.'<li class="menu-item-'.$l['language_code'].'"><a href="'. $l['url'].'">'. strtoupper( $l['language_code'] ).'</a></li>';
                }
            }
        }
    }
    return $items;
}
add_filter( 'wp_nav_menu_items', 'new_nav_menu_items309676',10,2 );

And it adds the language code link to main navbar-menu but won't add it to mobile menu.
How can I also add these language code -links to my mobile menu?

Thanks!

Share this post


Link to post
Share on other sites
ketri

It seems like I solved it:

 

 

1. Go to yoursite.com/wp-admin/nav-menus.php
Select your created menu for:

Main nav section
Mobile navigation

 

2 select the created nav for the navbar

 

3. functions.php:

// add shortened language codes to the navbar
function new_nav_menu_items309676($items,$args) {
    if (function_exists('icl_get_languages') && $args->theme_location == 'main_nav') {
        $languages = icl_get_languages('skip_missing=0');
        if(1 < count($languages)){
            foreach($languages as $l){
                if( $l['active'] != 1 ) { 
                    $items = $items.'<li class="menu-item-'.$l['language_code'].'"><a href="'. $l['url'].'">'. strtoupper( $l['language_code'] ).'</a></li>';
                }
            }
        }
    }
    return $items;
}
add_filter( 'wp_nav_menu_items', 'new_nav_menu_items309676',10,2 );


// add shortened language codes to the mobile nav
function new_nav_menu_items3096762($items,$args) {
    if (function_exists('icl_get_languages') && $args->theme_location == 'mobile_nav') {
        $languages = icl_get_languages('skip_missing=0');
        if(1 < count($languages)){
            foreach($languages as $l){
                if( $l['active'] != 1 ) { 
                    $items = $items.'<li class="menu-item-'.$l['language_code'].'"><a href="'. $l['url'].'">'. strtoupper( $l['language_code'] ).'</a></li>';
                }
            }
        }
    }
    return $items;
}
add_filter( 'wp_nav_menu_items', 'new_nav_menu_items3096762',10,2 );

Seems to work

Share this post


Link to post
Share on other sites
Danny

Thanks for informing us the issue has been resolved.


Please search our forums, before posting!

Share this post


Link to post
Share on other sites

×