Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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

This comment has been minimized.

Copy link
Owner Author

@om4james om4james commented May 5, 2012

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