Jump to content

Archived

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

janpeeters

Translate header logo

Recommended Posts

janpeeters+    31
janpeeters

Hi,

 

I'm trying to tackle an old problem that I left alone for a while.

 

On my website www.janpeeters.nl I use a text logo for my companies name ('Energiek leren') in the Dutch language. I want this logo to be shown in English ('Energetic Learning') when I switch to English. I'm using the latest version of Polylang (1.5)

My menu's (in the NavBar-Full section) translate properly but I've not found a way to swap the header image according to language.

 

I have connected the Dutch and English versions of the logo via de Polylang language box when you edit an image. But that didn't help.

 

Thanks for any suggestions.

 

Jan

 

DMS Pro 2.1.1

Share this post


Link to post
Share on other sites
Simon    247
Simon

All options are filterable.

 

https://gist.github.com/Pross/00f3cf95ed6accdcce5d

 

That code is untested, but you get the idea.

Share this post


Link to post
Share on other sites
janpeeters+    31
janpeeters

Thanks Simon, I will try this and report back.

 

Update:

I altered the code like this:

<?php
// we are going to filter navbar_logo section option on the fly..
add_filter( 'pl_opt-navbar_logo', 'change_logo_on_lang' );
function change_logo_on_lang( $val ) { // $val is the value of the setting.
 
// use some polylang data to get current language
global $curlang;
$curlang = $this->curlang->slug;
 
// asumming the slug is nl or en
 
if( 'en' == $curlang )
return 'http://www.janpeeters.nl/cms/wp-content/uploads/energetic_learning.png';
else
return 'http://www.janpeeters.nl/cms/wp-content/uploads/energiek_leren.png';
}

But my site breaks. I've added it to my child theme's functions.php.

I think I understand what the code does, but I've not been able to determine why it would break the site. 

Maybe you have some additional suggestions.

 

Thanks, Jan

Share this post


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

Remove the <?php tag at the top from the code and see if this resolves your issue.


Please search our forums, before posting!

Share this post


Link to post
Share on other sites
janpeeters+    31
janpeeters

Hi Danny, no helas it doesn't.

 

My functions.php looks like this and gives me a blank site:

<?php

// we are going to filter navbar_logo section option on the fly..
add_filter( 'pl_opt-navbar_logo', 'change_logo_on_lang' );
function change_logo_on_lang( $val ) { // $val is the value of the setting.
 
// use some polylang data to get current language
global $curlang;
$curlang = $this->curlang->slug;
 
// asumming the slug is nl or en
 
if( 'en' == $curlang )
return 'http://www.janpeeters.nl/cms/wp-content/uploads/energetic_learning.png';
else
return 'http://www.janpeeters.nl/cms/wp-content/uploads/energiek_leren.png';
}

?>

Share this post


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

Functions.php shouldn't end PHP using the ?> unless the hook requires it.

 

It should look like this:

 

https://cloudup.com/cefF1o4OHsO


Please search our forums, before posting!

Share this post


Link to post
Share on other sites
janpeeters+    31
janpeeters

Hi Danny,

 

removed the ?> at the end, but still no go. I get a blank page when loading the frontend of my website. Loading of Wordpress admin works well. 

I have no clue what causes the problem.

 

Are you absolutely sure the filter is the right one?

 

Thanks for your help, Jan

Share this post


Link to post
Share on other sites
Simon    247
Simon

if its a blank page, enable debug to see what the error is.

Share this post


Link to post
Share on other sites
janpeeters+    31
janpeeters

Hi Simon_P,

 

I enabled WP_DEBUG and it's log functionality. It says:

 

[21-Jun-2014 08:54:19 UTC] PHP Fatal error:  Using $this when not in object context in /home/janpeete/domains/janpeeters.nl/public_html/cms/wp-content/themes/dms-base/functions.php on line 9

 

Does that give any clue?

 

Thanks, Jan

Share this post


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

OK, can you take a screenshot of your base themes functions.php file please.


Please search our forums, before posting!

Share this post


Link to post
Share on other sites
janpeeters+    31
janpeeters

Of course. It's the same as above though, but just to be sure...

 

Base_functionsphp.png

Share this post


Link to post
Share on other sites
janpeeters+    31
janpeeters

Hi Danny,

 

I'm curious if my screenshot gave you additoinal insight into what I'm doing/is going wrong.

In DMS1 there was a textual blog title in the header which could be easily translated via Polylang strings. But with it being an image now in DMS 2 instead of text it is not possible to translate it easily. So I hope to get this image replacement filter to work.

 

Thanks for your help, Jan

Share this post


Link to post
Share on other sites
Simon    247
Simon

global $curlang;
$curlang = $this->curlang->slug;

 

should probably be

 

global $curlang;
$curlang = $curlang->slug;

Share this post


Link to post
Share on other sites
janpeeters+    31
janpeeters

Hi Simon_P, thanks for your help. It gives me the following error though:

 

Notice: Trying to get property of non-object in /home/janpeete/domains/janpeeters.nl/public_html/cms/wp-content/themes/dms-base/functions.php on line 9 Notice: Trying to get property of non-object in /home/janpeete/domains/janpeeters.nl/public_html/cms/wp-content/themes/dms-base/functions.php on line 9

 

Thanks for any additional ideas.

 

Jan

Share this post


Link to post
Share on other sites
Simon    247
Simon
Well I got that code off google
Maybe you have to ask polylang people how to get current language via php


Sent from my iPad using Tapatalk

Share this post


Link to post
Share on other sites
janpeeters+    31
janpeeters

Okay I'll do that. Thanks

Share this post


Link to post
Share on other sites
greenfly    230
greenfly

Let us know how you get on please.


The answer to many issues can be found by searching in the forum before posting as someone else  may very well have had the same problem before you have.  Also, reading the documentation can help you gain a good understanding of how everything works. 

 

Please do not send me private messages. Occam's razor - The principle states "Keep things simple!"

Share this post


Link to post
Share on other sites

  • Similar Content

    • Lisa Haran
      By Lisa Haran+
      Hi 
      I have a map here http://www.iloveoffset.com/maps/
      I want to add several pointer locations to the map, but when I do they do not appear.
      On this map there are 2 pointer locations and as you can there is only one visible.
      Earlier today I added 7 and could only see 4 so there is something odd going on.
      My theme is up to date
    • clj182
      By clj182+
      Hello,
      I've been having trouble unlocking the template section for past couple of weeks. When I try clicking nothing happens. 
      I've deleted my custom css and removed plugins. Im down to having only the following plugins:
      Akismet
      Contact Form 7
      DMS Professional Tools
      Pagelines Updater
      WooCommerce
      It was working fine before i have no idea what's going on with it.
    • flourishdesignstudio
      By flourishdesignstudio
      My DMS 2 site http://www.heart-stone.com/ will not save any new custom css... I can still edit templates and publish those but any custom css that I enter never saves.
      All WP files, themes, and plugins are up to date. 
      Any thought about what might be causing this?
    • flourishdesignstudio
      By flourishdesignstudio
      Is there a way to edit the custom CSS via FTP? I know I can edit the custom code in the Chrome editor but is there a file path I can use to find and edit the CSS directly from our FTP?
      Thanks in advance for the help!
    • nizami
      By nizami+
      Using navbar section with correctly configured WP menu to display main navigation at https://elenaangel.com. 
      All fine in desktop viewport. Menu displays twice in hamburger mode. How to fix this please? 

×