php - Wordpress different language footer text

admin2025-01-07  4

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.

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.

Share Improve this question edited Aug 28, 2018 at 6:10 nmr 4,5212 gold badges17 silver badges25 bronze badges asked Aug 27, 2018 at 10:14 BR ManagementBR Management 215 bronze badges 9
  • Welcome to WPSE. Unfortunately, your issue seems to be with the Polylang plugin, not with WordPress in general. You're more likely to get an answer at the plugin author's forum: wordpress.org/support/plugin/polylang – cjbj Commented Aug 27, 2018 at 10:23
  • I don't think that the problem is with poly lang, because the free version of polylang probably doesn't have this function for subfooter. I think you can change the footer with polylang, add it as widget for different languages, but not for subfooter. I tried various 'if-else' codes in Edit footer.php, but it didn't work. – BR Management Commented Aug 27, 2018 at 11:01
  • You mean the subfooter text is hardcoded in the theme? – cjbj Commented Aug 27, 2018 at 11:03
  • I changed the original text in the theme "Powered by..." to my in footer.php and added the link for the text to new site, but only in my primary language. Now when you choose another language, the subfooter text doesn't change. – BR Management Commented Aug 27, 2018 at 11:10
  • 1 If you have found the answer, please include it as an answer and accept it. If you do it as an edit to the question, this question will remain flagged 'unsolved' in the database. – cjbj Commented Aug 27, 2018 at 15:38
 |  Show 4 more comments

1 Answer 1

Reset to default 0

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(' | %s | %s | <a href="%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.

转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1736257908a473.html

最新回复(0)