如果我注册了一个帖子类型,那么我应该使用哪个转义来转义标签?
function book_setup_post_type() {
$args = array(
\'public\' => true,
\'label\' => __( \'Books\', \'textdomain\' ),
\'menu_icon\' => \'dashicons-book\',
);
register_post_type( \'book\', $args );
}
add_action( \'init\', \'book_setup_post_type\' );
最合适的回答,由SO网友:Jacob Peattie 整理而成
没有一个转义应该在输出时延迟发生。这只是注册字符串以供以后使用,因此现在退出还为时过早。WordPress中自动使用post类型标签的所有位置,WordPress应该已经对其进行了转义。
如果您自己输出任何标签,您可能会使用esc_html():
$post_type_object = get_post_type_object( \'book\' );
$post_type_labels = get_post_type_labels( $post_type_object );
echo esc_html( $post_type_labels->singular_name );