Skip to content

Instantly share code, notes, and snippets.

@thejamescollins
Created May 5, 2012 00:02
Show Gist options
  • Save thejamescollins/2598625 to your computer and use it in GitHub Desktop.
Save thejamescollins/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>';
@thejamescollins
Copy link
Author

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