WordPress different language footer text

I am new to WordPress, and I have a problem building my website. I use the Sydney theme and Polylang plugin for my multilanguage website.

I have build a website in 4 different languages and now I would like to have a different footer text for every language in the sub footer part.

For e.g. where it says in English language ‘Copyright I Privacy policy‘ ‘, with the hyperlink on provacypolicy/en, that I have created. For the German start page the subfooter language should auto change in ‘Copyright I Datenschutz‘, with the hyperlink from Datenschutz on the German page with privacypolicy/de that I have created. And also the same for the other languages.

I tried to edit that in the footer.php but I had no luck.

My existing code for <div class="site-info container"> in footer.php is:

© <?php echo date("Y"); ?> | Company name | All rights reserved | <a href=
"http://localhost/companyname/wordpress/privacy-policy/">Privacy policy</a> 

When I go to my german language it should change to:

© <?php echo date("Y"); ?> | Company name | Alle Rechte vorbehalten | <a href=
"http://localhost/companyname/wordpress/datenschutz/">Datenschutz</a>

And the same for other two languages.


I RESOLVED THE ISSUE.

For anyone that will have the same problem, use the if - endif code in your footer.php.

enter image description here

1 Answer
1

For the text in the theme to be able to be translated, the text should be passed as an argument through the localization functions __(), _e().

echo __( ‘Sample text to display’, ‘theme-textdomain’ );
_e( ‘Sample text to display’, ‘theme-textdomain’ );

More functions and details you can find here


In your case it could look like this:

© <?php 
echo date("Y"); 
$page_id = 'ID_of_privacy_policy_page';

if ( function_exists('pll_get_post') )
    $page_id = pll_get_post( $page_id );
$p_link = get_the_permalink($page_id);
$p_title = get_post_field('post_title', $page_id);

printf(' "https://wordpress.stackexchange.com/questions/312590/%s" %s | <a href="https://wordpress.stackexchange.com/questions/312590/%s">%s</a>', 
    'Company name',
    __('All rights reserved', 'some_textdomain'),
    esc_url($p_link),
    esc_html($p_title)
);

$page_id can be hardcoded or set with $page_id = get_page_by_path('privacy-policy')->ID;.

$page_id = pll_get_post( $page_id );

The obove line will get ID of “Privacy policy” page in current language.

The next step is to prepare a files with the translation de_DE.po, de_DE.mo and for 2 other languages. Edit existing files in your theme or create new ones if needed. A list of sample tools is available on the codex website, among others Loco Translate, Poedit.

Leave a Comment