我有一个带有高级自定义字段插件的 WYSIWG 字段。当我查询它时:
<p class="bran-hn news-excerpt"><?php echo custom_field_excerpt('news_post'); ?></p>
输出如下所示:
<p class="bran-hn news-excerpt"></p>
<p>Worf, It's better than music. It's jazz. Mr. Crusher, ready a collision course with the Borg ship. This is not about revenge. This is about justice. The Federation's gone; the Borg is everywhere! In all trust, [...]</p>
<p></p>
但我本来期望并想要类似的东西:
<p class="bran-hn news-excerpt">Worf, It's better than music. It's jazz. Mr. Crusher, ready a collision course with the Borg ship. This is not about revenge. This is about justice. The Federation's gone; the Borg is everywhere! In all trust, [...]</p>
我试图添加
$text = strip_tags ($text);
在 strip_shortcodes 调用查询所见即所得自定义字段的函数之前:
function custom_field_excerpt($title) {
global $post;
$text = get_field($title);
if ( '' != $text ) {
$text = strip_shortcodes( $text );
$text = apply_filters('the_content', $text);
$text = str_replace(']]>', ']]>', $text);
$excerpt_length = 35; // 20 words
$excerpt_more = apply_filters('excerpt_more', ' ' . '[...]');
$text = wp_trim_words( $text, $excerpt_length, $excerpt_more );
}
return apply_filters('the_excerpt', $text);
}
但也没有效果。那么有没有办法去除包装 p 标签,同时将可能的标签保留在字符串文本主体内,例如链接标签。最好的问候拉尔夫