admin管理员组

文章数量:1336091

I have two translatable strings as follows in my 404.php file

esc_html_e( 'I couldn't find the page you were looking for.', 'themename' );
esc_html_e( 'Try a search or one of the links below.', 'themename' );

At its present form, the first string does not get translated. Escaping the single quote with a backslash does not help either.

Any ideas?

I have two translatable strings as follows in my 404.php file

esc_html_e( 'I couldn't find the page you were looking for.', 'themename' );
esc_html_e( 'Try a search or one of the links below.', 'themename' );

At its present form, the first string does not get translated. Escaping the single quote with a backslash does not help either.

Any ideas?

Share Improve this question edited May 28, 2020 at 17:28 user1438038 1761 silver badge12 bronze badges asked Jun 18, 2016 at 9:53 developerdeveloper 1516 bronze badges 2
  • Easiest way out is simply write 'could not', though there's probably a smarter way. – cjbj Commented Jun 18, 2016 at 10:03
  • Right, but that makes it formal. Besides, I prefer to know a solution to this problem in terms of programming and learn something. Thanks anyway. – developer Commented Jun 18, 2016 at 10:09
Add a comment  | 

2 Answers 2

Reset to default 0

You can wrap it inside double quotes:

esc_html_e("I couldn't find the page you are looking for.", "themename");

You can also escape the single quote:

esc_html_e( 'I couldn\'t find the page you were looking for.', 'themename' );

But the PHP Coding Standards of WordPress recommend to not escape any characters:

Single and Double Quotes

Use single and double quotes when appropriate. If you’re not evaluating anything in the string, use single quotes. You should almost never have to escape quotes in a string, because you can just alternate your quoting style.

So you are probably better of, using double quotes as stated by user6454281 already:

esc_html_e( "I couldn't find the page you were looking for.", 'themename' );

本文标签: translationHow to handle single quote in a translatable string in Wordpress