JSON结构化数据描述显示了html标签

时间:2017-08-24 13:48:07

标签: json wordpress strip structured-data

在我们的网站上,我们使用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>

1 个答案:

答案 0 :(得分:0)

要删除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)‌​); ?>