Skip to content

Instantly share code, notes, and snippets.

@om4james
Created May 5, 2012 00:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save om4james/2598625 to your computer and use it in GitHub Desktop.
Save om4james/2598625 to your computer and use it in GitHub Desktop.
WordPress String Translation Escaping Example
<?php
echo '<p>' . __('This is some text that needs to be translatable in my WordPress plugin', 'myplugin') . '</p>';
<?php
echo '<p>' . esc_html__('This text is still translatable in my WordPress plugin, but it also safe because it is escaped before being output.', 'myplugin') . '</p>';
<?php
echo '<a href="#" title="' . __('The title attribute in this link needs to be translatable', 'myplugin') . '">' . __('The anchor text also needs to be translatable', 'myplugin') . '</a>';
<?php
echo '<a href="#" title="' . esc_attr__('The title attribute in this link needs to be translatable', 'myplugin') . '">' . esc_html__('The anchor text also needs to be translatable', 'myplugin') . '</a>';
@om4james
Copy link
Author

om4james commented May 5, 2012

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment