If you have strings that should be translatable, but they’re wrapped in HTML markup, WordPress has several designated gettext functions you should use. These functions properly escape any HTML reserved characters so that the HTML output displays properly in a browser. Carrie shows you examples of how this works.
- [Voiceover] Now that you've seen…the two basic translation functions,…the double underscores for returning strings…and the underscore E for echoing strings,…there's a couple more string translation functions…I'd like to introduce you to.…They're the counterparts to these…two functions we just looked at.…The difference is that you use these…when there's HTML output involved.…Here, we're adding the ecs underscore HTML to the beginning…of either one of those functions to escape HTML output.…If you're not familiar with escaping HTML output,…it basically goes like this.…
HTML has some special reserved characters…such as the greater than or less than signs…used for HTML tags.…If you include one of those signs in your text…meaning to actually use it as, say, a greater than sign,…the browser could confuse it for an HTML tag.…To properly display those reserved characters,…we use something called HTML entities.…Escaping HTML, then, means that those reserved characters…stay HTML instead of accidentally getting converted…
- Why internationalization is important
- Using the gettext() function
- Adding context for translations
- Adding and loading text domains for WordPress themes and plugins
- Translating using GlotPress