• 0

DMS 2 Translate header logo


Question

Posted · Report post

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

17 answers to this question

  • 0

Posted · Report post

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
  • 0

Posted (edited) · Report post

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

Edited by janpeeters

Share this post


Link to post
Share on other sites
  • 0

Posted · Report post

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

Share this post


Link to post
Share on other sites
  • 0

Posted · Report post

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
  • 0

Posted · Report post

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

 

It should look like this:

 

https://cloudup.com/cefF1o4OHsO

Share this post


Link to post
Share on other sites
  • 0

Posted · Report post

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
  • 0

Posted · Report post

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

Share this post


Link to post
Share on other sites
  • 0

Posted · Report post

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
  • 0

Posted · Report post

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

Share this post


Link to post
Share on other sites
  • 0

Posted · Report post

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
  • 0

Posted · Report post

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
  • 0

Posted · Report post

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

 

should probably be

 

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

Share this post


Link to post
Share on other sites
  • 0

Posted · Report post

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
  • 0

Posted · Report post

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
  • 0

Posted · Report post

Okay I'll do that. Thanks

Share this post


Link to post
Share on other sites
  • 0

Posted · Report post

Let us know how you get on please.

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