【问题标题】:JSON structured data description shows html tagsJSON结构化数据描述显示html标签
【发布时间】:2018-02-02 10:31:07
【问题描述】:

在我们的网站上,我们使用 JSON 来显示我们的结构化数据。其中一个字段 (reviewBody) 返回 p 标签内的文本。我想删除开始和结束标签。

谁能帮我去掉标签?

<script type="application/ld+json">
{
    "@context": "http://schema.org",
    "@type": "Review",
    "image": "<?php echo get_the_post_thumbnail_url(); ?>",
    "reviewBody": <?=json_encode(apply_filters('the_content', $tw_entry->review_summary)); ?>,
    "description": "<?php echo get_post_meta(get_the_ID(), '_yoast_wpseo_metadesc', true); ?>",
    "datePublished": "<?php echo get_the_date('Y-m-d'); ?>",
    "itemReviewed": {
        "@type": "Thing",
        "name": "<?php the_title(); ?>"
    },
    "author": {
        "@type": "Person",
        "name": "mr x"
    },
    "reviewRating": {
        "@type": "Rating",
        "bestRating": "10",
        "ratingValue": "<?php echo get_post_meta($post->ID, 'average-rating', true)/10; ?>",
        "worstRating": "1"
    } 
}
</script>

结果:

"reviewBody": <p>lorem ipsum</p>

【问题讨论】:

  • 你的意思是没有html标签?只有内容?
  • 是的,我需要 '

    ' 和 '

    ' 去。所以我只会留下“lorem ipsum”
  • 把这个&lt;?=json_encode(apply_filters('the_content', $tw_entry-&gt;review_summary)); ?&gt;改成这个&lt;?php echo json_encode(wp_filter_nohtml_kses($tw_entry-&gt;review_summary)); ?&gt;
  • 谢谢诺曼先生,就是这样!今天的救星!
  • 你能接受答案吗?如果是,那么我将添加为答案

标签: json wordpress strip structured-data


【解决方案1】:

要剥离html,你需要使用wp_filter_nohtml_kses 所以,改变这个

<?=json_encode(apply_filters('the_content', $tw_entry->review_summary)); ?> 

到这里

<?php echo json_encode(wp_filter_nohtml_kses($tw_entry->review_summary)‌​); ?>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-11-02
    • 1970-01-01
    • 2022-11-30
    • 1970-01-01
    • 2015-03-13
    相关资源
    最近更新 更多