How should I properly escape the single quote character in a translation string? I'm using it as an apostrophe. For example:

__( '404. This isn't the page you're looking for.', 'textdomain' );

I believe there are a few approaches but which is the proper way?

Approach 1: Using the backslash:

__( '404. This isn\'t the page you\'re looking for.', 'textdomain' );

Approach 2: Using the character entity:

__( '404. This isn't the page you're looking for.', 'textdomain' );
  • What does proper mean? How about double quotes?
    – janevu
    Jun 26 '16 at 10:39
  • 1
    Sorry, think it may be my British. Proper "of the required or correct type or form; suitable or appropriate." Jun 26 '16 at 10:49

Use the first option. translated strings are supposed to be "raw", and escaped only by the calling function. In addition many will not understand what ' mean and how to translate it without looking at the actual page which can be annoying.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.