无论我做什么(是否剥离html标记),以下语句都会在两行而不是一行上显示结果:
$text = sprintf( \'<p>%1$s %2$s</p>\', wp_filter_nohtml_kses( the_author_meta(\'user_firstname\') ), __( \'hasn\\\'t published any articles yet.\', \'monochrome-pro\' ) );
知道为什么会这样吗?无论我做什么(是否剥离html标记),以下语句都会在两行而不是一行上显示结果:
$text = sprintf( \'<p>%1$s %2$s</p>\', wp_filter_nohtml_kses( the_author_meta(\'user_firstname\') ), __( \'hasn\\\'t published any articles yet.\', \'monochrome-pro\' ) );
知道为什么会这样吗?请注意the_author_meta()
不会返回meta值,但会回显它。这就是为什么这个名字突然在<p>
要素
使用get_the_author_meta()
如果需要返回(并处理)字段,而不仅仅是显示它。
我强烈建议您更改__()
同样,因为这对翻译人员没有用处,因为它缺少作为上下文的名称。
/* translators: %s: user\'s first name */
$text = sprintf(
__( "%s hasn\'t published any articles yet.", \'monochrome-pro\' ),
esc_html( get_the_author_meta( \'user_firstname\' ) )
);
echo \'<p>\' . $text . \'</p>\';
注意:如果你不信任你的翻译,你应该使用esc_html()
在…上$text
而不是用户元。正如评论中提到的,使用KSES函数有点过头了。如果您想去掉任何HTML标记(而不是仅仅转义它们),我会使用wp_strip_all_tags()
.我遇到过人们使用esc_html() 或esc_url() 具有某些WP功能,如home_url(\'/\'). 示例位于<a> 链接回主页,例如:<a href=\"<?php echo esc_url( home_url( \'/\' ) ); ?>\"> 您如何知道哪些WP函数需要转义,如果您使用esc_html() 或esc_url()?任何建议或指导都会很好。
无论我做什么(是否剥离html标记),以下语句都会在两行而不是一行上显示结果:
$text = sprintf( \'<p>%1$s %2$s</p>\', wp_filter_nohtml_kses( the_author_meta(\'user_firstname\') ), __( \'hasn\\\'t published any articles yet.\', \'monochrome-pro\' ) );
知道为什么会这样吗?请注意the_author_meta()
不会返回meta值,但会回显它。这就是为什么这个名字突然在<p>
要素
使用get_the_author_meta()
如果需要返回(并处理)字段,而不仅仅是显示它。
我强烈建议您更改__()
同样,因为这对翻译人员没有用处,因为它缺少作为上下文的名称。
/* translators: %s: user\'s first name */
$text = sprintf(
__( "%s hasn\'t published any articles yet.", \'monochrome-pro\' ),
esc_html( get_the_author_meta( \'user_firstname\' ) )
);
echo \'<p>\' . $text . \'</p>\';
注意:如果你不信任你的翻译,你应该使用esc_html()
在…上$text
而不是用户元。正如评论中提到的,使用KSES函数有点过头了。如果您想去掉任何HTML标记(而不是仅仅转义它们),我会使用wp_strip_all_tags()
.我有这个HTML <div class=\"navbartop\"> <a href=\"/\">Home</a> <div class=\"subnavtop\"> <button class=\"subnavtopbtn\">Alfabetic <i class=\"fa fa-caret-down\"></i></button> <div