Escaping Text With Links In WordPress – The Right Way


Escaping a text with links can be replaced if escaped with __() during localization. This not ideal since the person writing the localizing file could replace links with their own.

The proper way to do this is explained with an example below:

sprintf( __( 'If you like this plugin, please <a href="" target="_blank">make a donation</a> or leave a <a href="" target="_blank">&#9733;&#9733;&#9733;&#9733;&#9733;</a> rating to support continued development. Thanks a bunch!', 'text_domain' ),

Only the text part is escaped, the links aren’t. Of course the translator can choose not to display any links at all. Hmm, evil.

To print the same replacing _e() use printf instead of sprintf.


Leave a Reply

Random Post Selection ::

Recent Posts

Unlock Unlimited Downloads