I’m trying to create multilanguage wordpress site. In functions.php I have custom breadcrumbs
$text['home'] = 'Main'; // text for Main
$text['category'] = '%s'; // text for category
if ($show_home_link == 1) echo sprintf($link, $home_link, $text['home']);
I want to put _e function to word ‘Main’, generate .po file and change word ‘Main’ to selected language.
I trying to use
<?php _e('Main', TemplateName); ?>
instead of ‘Main’ such as
$text['home'] = '_e('Main', TemplateName)'; // text for Main
but I get _e(‘Main’, TemplateName) instead of Main.
Give an advice please, how can I do it? I know, the problem is syntax, I’m very new in php.
Thank you.
Using
<?php _e('Main', 'TemplateName'); ?>
you display a translated stringMain
.If you want to store the value in a variable, you need to use
<?php $text['home'] = __('Main', 'TemplateName'); ?>
When you wrap the function in single quotes you are basically asking PHP to treat it as a literal string. You need to do
because the
__()
function will already return a string based on your PO file. You also need to wrapTemplateName
in quotes if that is the name of your theme.Since you have stated you are very new to PHP, do take the time to write your own code first (outside of WordPress) and understand the syntax and how to work around variables first. Good luck.
EDIT: Thanks Bondye for pointing out that
_e
echoes rather than returns. I’ve lost touch for a while.