转义用于元描述的html

时间:2016-08-23 作者:JoaMika

我正在使用此代码向我的帖子中添加来自自定义字段的元描述。

$des = get_post_meta( get_the_id(), \'fl_description\', true);
  if( ! empty( $des )  ){
    $meta_des = esc_html($des);
    echo \'<meta name="description" content="\' . $meta_des . \'" />\';
然而,我需要完全避开所有html标记和短代码。i、 e输入

<p><span class="x-dropcap">D</span>esigned by interior mastermind Chams it is one of the only top <strong>members</strong> clubs where partying and dining co-exist under one roof. </p>
需要成为:

Designed by interior mastermind Chams it is one of the only top members clubs where partying and dining co-exist under one roof. 

1 个回复
最合适的回答,由SO网友:MadtownLems 整理而成

要剥离HTML标记和短代码,请结合使用PHP的strip\\u标记(http://php.net/manual/en/function.strip-tags.php ) 和WordPress的strip\\u短代码(https://codex.wordpress.org/Function_Reference/strip_shortcodes )

$meta_des = strip_shortcodes( strip_tag( $des ) );