Jump to content
Sign in to follow this  
peters_publishing

WPML Language Selector in Header, with Hooks

Recommended Posts

peters_publishing

Hello, I'm trying to use the solution that Benoit offers here for putting a language selector in the header. I inserted this code into functions.php: // add_action('hook_name','function name'); add_action('pagelines_inside_bottom_branding', 'add_langselector_to_branding'); // function name function add_langselector_to_branding(){ function language_selector_flags(){ $languages = icl_get_languages('skip_missing=0&orderby=code'); if(!empty($languages)){ foreach($languages as $l){ if(!$l['active']) echo ''; echo ''.$l['language_code'].''; if(!$l['active']) echo ''; } } } ?> <div id="flags_language_selector"><?php language_selector_flags(); ?></div > <?php } // end function But I just get the abbreviations for the languages, w/o the selector, which you can see on my site here, just below the logo http://www.skypeenglishclasses.com/. I am using WordPress 3.1 with WPML 2.0.4.1 and PlatformPro Thanks!

Share this post


Link to post
Share on other sites
cmunns

Then you're probably not calling the function for the language selector correctly. Also, you do still have it in the footer so make sure that the js doesn't conflict by having it in both locations.

Share this post


Link to post
Share on other sites
peters_publishing

I tried taking out of the footer, but had no luck. So I assume it's because of the way I'm calling the function. I'm honestly not sure what this means, really. The only thing I've done so far is add the code above.

Share this post


Link to post
Share on other sites
Andrew

We will be looking at specific support for WPML in a coming release, so stay tuned for that. did you check with the plugin creator?

Share this post


Link to post
Share on other sites
peters_publishing

Ok, so I've upgraded to the most recent version of WPML, which gives me a piece of code (below) to insert wherever I want my language selector to appear. So, where is the best place to put this code to get it to show in my header, above the social icons?

<?php do_action('icl_language_selector'); ?>

Share this post


Link to post
Share on other sites
cmunns

You may have to still apply CSS to position directly above the icons because my guess is that it's going to span full-width, but the hook location would be `pagelines_before_branding_icons`

Share this post


Link to post
Share on other sites
peters_publishing

Ok. I've watched the video on adding hooks. From what I can tell, I'd have to switch to the child base theme, then learn how to write custom hooks and put one in functions, then learn about CSS and write code to style it. Is there any simple way to get the language selector in my header? Or near it even?

Share this post


Link to post
Share on other sites
timlinson

The easiest solution is to wait for the upcoming release that Andrew mentioned. If you can't afford to wait, the next simplest solution is to use the hook that Adam mentioned. Basically you just make your function `do_action('icl_language_selector');` and then using the hook name that Adam gave you. As far as the CSS goes, you'll have to style it regardless unless you just wait for the built-in release.

Share this post


Link to post
Share on other sites
peters_publishing

What's the word on WPML support in the upcoming release? Has that happened yet? Is it imminent?

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this  

×