1

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.

asked Jun 3, 2015 at 9:28

2 Answers 2

2

Using <?php _e('Main', 'TemplateName'); ?> you display a translated string Main.

If you want to store the value in a variable, you need to use <?php $text['home'] = __('Main', 'TemplateName'); ?>

answered Jun 3, 2015 at 9:43
Sign up to request clarification or add additional context in comments.

Comments

1

When you wrap the function in single quotes you are basically asking PHP to treat it as a literal string. You need to do

$text['home'] = __('Main', 'TemplateName');

because the __() function will already return a string based on your PO file. You also need to wrap TemplateName 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.

answered Jun 3, 2015 at 9:33

1 Comment

_e() does not return a string, it displays a string. You probably looking for __()

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.