【发布时间】: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” -
把这个
<?=json_encode(apply_filters('the_content', $tw_entry->review_summary)); ?>改成这个<?php echo json_encode(wp_filter_nohtml_kses($tw_entry->review_summary)); ?> -
谢谢诺曼先生,就是这样!今天的救星!
-
你能接受答案吗?如果是,那么我将添加为答案
标签: json wordpress strip structured-data