When to use __() and esc_html_e

前端 未结 2 1662
醉话见心
醉话见心 2021-02-04 07:55

Can anyone explain why I would use __() over esc_html_e()

__() esc_html_e

2条回答
  •  甜味超标
    2021-02-04 08:33

    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 ) );
    }
    

提交回复
热议问题