Created
May 5, 2012 00:02
-
-
Save thejamescollins/2598625 to your computer and use it in GitHub Desktop.
WordPress String Translation Escaping Example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
echo '<p>' . __('This is some text that needs to be translatable in my WordPress plugin', 'myplugin') . '</p>'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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>'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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>'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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>'; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
These examples are explained here: http://jamesc.id.au/2012/05/escape-translated-strings-wordpress-plugin-theme/