Jump to content

Archived

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

yelenas

Placing WPML Language switcher in upper right header

Recommended Posts

yelenas    3
yelenas

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/forums/topic/again-how-to-add-the-language-switcher-into-header/ 

http://wpml.org/forums/topic/how-to-put-the-language-switcher-preview-in-the-header/ 

http://wpml.org/forums/topic/putting-a-language-switcher-in-the-header-of-the-flexography-theme/ 

http://wpml.org/forums/topic/language-switcher-in-header-7/ 

http://wpml.org/forums/topic/only-flag-language-switcher-in-header/ 
 

 

Thank you so much!

Share this post


Link to post
Share on other sites
Danny    1,327
Danny

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.pagelines.com/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.pagelines.com/customize/how-to-customize


Please search our forums, before posting!

Share this post


Link to post
Share on other sites
yelenas    3
yelenas

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!!!

Share this post


Link to post
Share on other sites
James B    436
James B

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.pagelines.com/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>

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
yelenas    3
yelenas

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>';
 
        }
 
    }
 
}

Share this post


Link to post
Share on other sites
James B    436
James B

Hi there, sorry not sure why the link didn't paste. https://github.com/bearded-avenger/nicks-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'.


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
yelenas    3
yelenas

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?

Share this post


Link to post
Share on other sites
James B    436
James B

Hi there, you won't need to create them again, simply install the child theme from https://github.com/bearded-avenger/nicks-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.


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
yelenas    3
yelenas

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?

Share this post


Link to post
Share on other sites
Danny    1,327
Danny

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.wordpress.org/Child_Themes

 

You should also read through our customization documentation too - http://docs.pagelines.com/customize/how-to-customize


Please search our forums, before posting!

Share this post


Link to post
Share on other sites

  • Similar Content

    • JP
      By JP+
      Hello,
      We are working on a 2 languages site (https://liguecardioliga.be) with wpml, and lately the call of a category in the loops section (and all the sections requiring a category to select posts) doesn't work in the translated language. It worked well until recently so I wonder if it's because of a recent update (wordpress, wpml, pagelines, a plugin?). Anyone has the same problem? a solution?
      TIA
    • mrhinsh
      By mrhinsh
      I am trying to get WPML working on my Pagelines instance. I am interested in getting help from anyone that has tried, especially @claudedagenais who seams to have it working.
      My issues are:
      How to translate header and footer How to get the menu to show all nav even if not translated How to get non-translated posts /pages to show up when only in default language - true for Masonry, Newsfront, and other list showing items... I have zero skills in PHP and its my site for my company. 
      note: Multi-lingual is a business decision and is required. I have vetted all of the multi-lingual options and the only one fit for purpose is WPML. 
    • JP
      By JP+
      Hello,
      How can you set the translations with platform5, the parts that are not in pages or posts? Texts and images…
    • claudedagenais
      By claudedagenais+
      Hello, we have this strange new problem with DMS2 when used with WPML. We can save our change to the section only in the main language. When trying to edit DMS sections in the other languages DMS won't let us save. The work around is to change the main language in WPML to the language you want to change and switch back afterward to the language you really want to be the main one.
      This is a new problem that did not exist before a few days ago. We are unsure if it is linked to the Wordpress 4.4 update, the WPML 3.3.3 Update or the DMS 2.2.1.1 update (!) that we did recently. We tried unsuccessfully deactivating everything (except WPML of course) including our child theme in a test environment. We can't turn off the DMS editor either from the other language pages. Some of the websites we are having this problem with are  http://www.artssutton.com/ , http://journalletour.com/, ...
      Tx
    • Ellery
      By Ellery
      I am using pageline (v2.2.1.1) and WPML (3.3.3). WP 4.3.1
      Here is the problem: when I set the language to be a path like this:
      http://localhost/pageline/zh-hant
      all [pl_site_url] will become above, which means, if you are using images in textbox, or pageheader, the full URL would become
      http://localhost/pageline/zh-hant/wp-content/upload......
      which is wrong.
      Furthermore, if the site requires AJAX, the calling URL becomes:
      http://localhost/pageline/zh-hant/wp-admin/admin-ajax.php
      which is also wrong.
      Now you may want me to use ?lang=zh-hant instead of using /zh-hant/, but it would become
      http://localhost/pageline/?lang=zh-hant/wp-admin/admin-ajax.php
      which is also wrong.
      Can you please tell me how to fix it?
      Thank you very much in advance for your help.
×