Jump to content


Photo
- - - - -

Placing WPML Language switcher in upper right header

Language Switcher Help with codes WPML

  • Please log in to reply
9 replies to this topic

#1 yelenas

yelenas

    Member

  • Members
  • PipPip
  • 12 posts
  • Country: Country Flag

Posted 08 February 2014 - 05:34 PM

Hello!

 

My website that I am helping with is:

 

http://test.cellalaw.com/cms/

 

 

I have been asked to put the language switcher for the translator plug in WPML in the upper right hand corner. I have read some forums but I am not sure exactly how to do this with Pagelines without accessing the FTP Files (the hosting company won't give me access to these). 

 

I just learned about the Custom CSS - is there any way I can put a code in the CSS to accomplish this without getting to the FTP "header" file?

 

Here is some resources that I looked at:

 

https://wpml.org/for...er-into-header/ 

http://wpml.org/foru...-in-the-header/ 

http://wpml.org/foru...xography-theme/ 

http://wpml.org/foru...er-in-header-7/ 

http://wpml.org/foru...cher-in-header/ 
 

 

Thank you so much!



#2 Danny

Danny

    Is Awesome!

  • Moderators
  • 15269 posts
  • LocationManchester, UK
  • Country: Country Flag

Posted 09 February 2014 - 11:08 AM

Hi,

 

What you want to do, ( I haven't used the the WPML plugin ) is use a hook to add the following code to your site.

 

do_action('icl_language_selector');

 

Hooks, require a child theme and you can add/edit code via the Wordpress editor. However, FTP/STP access, would be better due to the fact that when you use FTP, you edit the file with your code editor. Any mistakes made can be reverted by simply selecting Undo. You can learn more about hooks here - http://docs.pageline.../advanced/hooks

 

Then add the CSS if any is required to either the Custom tab in DMS toolbar or your child themes style.css file. You can learn more about customizing DMS here - http://docs.pageline...ow-to-customize



#3 yelenas

yelenas

    Member

  • Members
  • PipPip
  • 12 posts
  • Country: Country Flag

Posted 20 February 2014 - 01:27 AM

Danny:

 

Thank you for the response. 

 

I got access to the FTP files - I have tried a few things and I can't seem to get the language switcher to show up in the upper right header.

 

I tried adding the following to my Functions.php File but I am not sure where to put it in the sequence:

 

 

function language_selector(){
 
    $languages = icl_get_languages('skip_missing=0&orderby=code');
 
    if(!empty($languages)){
 
        foreach($languages as $l){
 
            if(!$l['active']) echo '<a href="'.$l['url'].'">';
 
            echo '<img src="'.$l['country_flag_url'].'" height="12" alt="'.$l['language_code'].'" width="18" style="margin:1px; border:1px solid #333;"/> '.$l['native_name'];
 
            if(!$l['active']) echo '</a>';
 
        }
 
    }
 
}
 
 
I also added the following to the header.php File
 
<?php wp_head(); ?> <?php do_action('icl_language_selector'); ?>; ?>
</head>
 
 
AND, I added this to the WPML Custom Additional CSS:
 
#flags_language_selector img{
      margin:1px;
      border:1px solid #333;
 
Nothing is showing up, do you have any pointers. Keep in mind I am very begginner in coding and files.
 
Thanks!!!


#4 James B

James B

    Advocate

  • Moderators
  • 5126 posts
  • LocationSurrey - UK
  • Country: Country Flag

Posted 20 February 2014 - 07:58 AM

Hi there, you'll need to install a child theme and add the code into the functions.php of the child theme. The base theme is a blank child theme and can be downloaded from

 

If you make changes to the core files, like the header.php and the functions.php of the main DMS theme, then when you update the theme in the future that code you entered will be wiped out. Using a child theme protects this.

 

The header code you will need to add using a hook, the code for the hook goes into the functions.php as well. More information on hooks and how they work can be found at http://docs.pageline.../advanced/hooks

 

In relation to the code below, you'll won't need to add the closing head tag, just the php line.

 

<?php wp_head(); ?> <?php do_action('icl_language_selector'); ?>; ?>
</head>


#5 yelenas

yelenas

    Member

  • Members
  • PipPip
  • 12 posts
  • Country: Country Flag

Posted 20 February 2014 - 05:57 PM

Please bear with me - I am a newbie with coding. But, I really need to figure out how to do this to finalize a website.

 

 

1. How do I install a child theme? I am using Filezilla to edit the FTP files - if that makes a difference. 

There was no link for the download, it said downloaded from "____________."

  • I have to do this for the header and functions files, correct?

 

2. Will the child "function.php" theme be a replica of the parent? or just blank and I will have to add <?php do_action('icl_language_selector'); ?> to it. If not - where is the code going in the file?

  • ie: before _____ and after ______.

 

3. Do I create a child page for the header file too? Also, is this same code going into the "child header file" <?php do_action('icl_language_selector'); ?> 

 

 

4. Is <?php do_action('icl_language_selector'); ?> the hook I need? Or am I looking for something else?

 

 

5. Do I still need the following in the Additional CSS (WPML Plug in settings)

 

 

#flags_language_selector img{
      margin:1px;
      border:1px solid #333;
 
 
6. What about the following code into the (Child?) functions.php file?
 
function language_selector(){
 
    $languages = icl_get_languages('skip_missing=0&orderby=code');
 
    if(!empty($languages)){
 
        foreach($languages as $l){
 
            if(!$l['active']) echo '<a href="'.$l['url'].'">';
 
            echo '<img src="'.$l['country_flag_url'].'" height="12" alt="'.$l['language_code'].'" width="18" style="margin:1px; border:1px solid #333;"/> '.$l['native_name'];
 
            if(!$l['active']) echo '</a>';
 
        }
 
    }
 
}


#6 James B

James B

    Advocate

  • Moderators
  • 5126 posts
  • LocationSurrey - UK
  • Country: Country Flag

Posted 21 February 2014 - 06:10 AM

Hi there, sorry not sure why the link didn't paste. https://github.com/b...icks-base-theme

 

The functions php file in the base theme will be all set up, so you just have to paste in your required content. You'll still need to add the css specified by the plugin. 

 

It depends exactly where they're telling you to add the php line to as to which hook you'll use. If you contact the plugin author they'll usually provide you with the exact hook and the code required for the hook. If it was added to the header I would imagine they'd use 'wp_head'.



#7 yelenas

yelenas

    Member

  • Members
  • PipPip
  • 12 posts
  • Country: Country Flag

Posted 25 February 2014 - 05:27 PM

James: Thank you again for the response.

 

I have the functions.php and header.php files already in the FTP - but how do I create "child" pages of them?



#8 James B

James B

    Advocate

  • Moderators
  • 5126 posts
  • LocationSurrey - UK
  • Country: Country Flag

Posted 25 February 2014 - 11:48 PM

Hi there, you won't need to create them again, simply install the child theme from https://github.com/b...icks-base-theme and make it the active theme. This child theme already has the functions.php inside. So you can then go to wp admin > editor > nicks' base theme > functions.php and enter your code.



#9 yelenas

yelenas

    Member

  • Members
  • PipPip
  • 12 posts
  • Country: Country Flag

Posted 01 March 2014 - 05:14 PM

James:

 

So I would download the zip file of this theme and upload it in Plugins? 

 

Or where would I upload this child theme to to activate it? Can I do this using the wordpress platform (this would be better!!) or do I have to do it though the FTP?

 

Also - are there any additional steps to activate the child theme?



#10 Danny

Danny

    Is Awesome!

  • Moderators
  • 15269 posts
  • LocationManchester, UK
  • Country: Country Flag

Posted 02 March 2014 - 11:46 AM

No, you download that themes zip and upload as a theme, as it's a theme and not a plugin. Once uploaded, goto Wordpress Admin Dashboard > Appearance > Themes and then make that child theme your active theme, then you add any custom functions to that child themes functions.php file.

I highly recommend you read the Wordpress Codex article on child themes, as it will assist you.

 

https://codex.wordpr...rg/Child_Themes

 

You should also read through our customization documentation too - http://docs.pageline...ow-to-customize







Also tagged with one or more of these keywords: Language Switcher, Help with codes, WPML