This is the technical support forum for WPML - the multilingual WordPress plugin.

Everyone can read, but only WPML clients can post here. WPML team is replying on the forum 6 days per week, 22 hours per day.

This topic contains 4 replies, has 2 voices.

Last updated by Paul 6 months ago.

Assigned support staff: Riffaz.

Author Posts
April 8, 2019 at 12:00 pm #3557419

Paul

The WPML plugin has the neat option of automatically adding the language switcher at the end of the menu. In most cases that's fine.

However, for the MAIN Menu it is often the case that we want the FURTHEST RIGHT element in that part of the screen to be a Call-to-Action button/link.

How can I append such a link AFTER the menu switcher has appended itself?
I assume that there is a way to do so with some custom code in functions.php?
See page:
hidden link

Please note we ONLY want this CTA to appear in the Main Menu, not in the Nav Widget which is used in the footer.

April 8, 2019 at 12:48 pm #3557823

Riffaz
Supporter

Languages: English (English )

Timezone: Asia/Colombo (GMT+05:30)

Hi,

Thank you for contacting WPML support.

WPML uses default WordPress menu.
By default it does not add anything after the language switcher in default WP menu.

In this case, you have to create your own custom language.
We can guide you how to create it but we can not create it for you since it's really a custom work.
Please refer: https://wpml.org/documentation/getting-started-guide/language-setup/custom-language-switcher/

This also may help : https://wpml.org/forums/topic/adding-an-external-link-to-language-switcher/

If you are unable to get it work we highly recommend you to check this out : https://wpml.org/contractors/

Let me know you need anything else regarding this within the support scope.

Regards,
Riffaz.

April 9, 2019 at 1:56 am #3561947

Paul

OK. I got it to work like this:

function new_nav_menu_items($items)
{
	if (function_exists('icl_get_languages')){
		
		if ( defined( 'ICL_LANGUAGE_CODE' ) ) {
  			$this_language = ICL_LANGUAGE_CODE;
  			if ($this_language=='en'){
				$items .= '<ul><li class="menu-item menu-item-language nav-cta"><a class="nav-cta-link" href="#">EN CTA here</a></li></ul>';
			}
			if ($this_language=='ja'){
				$items .= '<ul><li class="menu-item menu-item-language nav-cta"><a class="nav-cta-link" href="#">JA CTA here</a></li></ul>';
			}
        }
	    
	   	return $items;
  		
    }
}
add_filter('wp_nav_menu_items', 'new_nav_menu_items');

When I used this:

$languages = apply_filters( 'wpml_active_languages', NULL, 'skip_missing=0&orderby=code' );
$current_language = apply_filters('wpml_current_language');

I got WSOD.

Are 'wpml_active_languages' and 'wpml_current_languages' valid?

April 10, 2019 at 12:25 pm #3575983

Riffaz
Supporter

Languages: English (English )

Timezone: Asia/Colombo (GMT+05:30)

Hi,

That's all good.
There is a small missing param.

you just need to supply the NULL

$current_language = apply_filters('wpml_current_language', NULL );

I recommend you to enable WP_DEBUG
So you can see the error messages while you are adding code.
when everything works, you can remove WP_DEBUG again

if you had WP_DEBUG turned on, you would seen "missing parameter" instead of a WSOD

Hopefully, this will help.

Regards,

April 10, 2019 at 12:39 pm #3576173

Paul

Thanks for ALL the advice.
Much appreciated.

You can close the ticket.