Can anyone explain why I would use __()
over esc_html_e()
__() esc_html_e
Just like the docs state, esc_html_e()
retrieves a translated string, escapes it, and echoes the result. __()
returns a translated string. The source for each of these functions makes this crystal clear:
function __( $text, $domain = 'default' ) {
return translate( $text, $domain );
}
function esc_html_e( $text, $domain = 'default' ) {
echo esc_html( translate( $text, $domain ) );
}