2017-08-24 71 views
0

在我們的網站上,我們使用JSON來顯示我們的結構化數據。其中一個字段(reviewBody)返回p標籤內的文本。我想刪除打開和關閉標籤。JSON結構化數據描述顯示html標記

誰能幫我脫標籤?

<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> 
+0

你的意思是沒有HTML標籤?只有內容? – Noman

+0

是的,我需要'

'和'

'去。所以我只會繼續與「lorem ipsum」 – DreadyE

+0

改變這個'<?= json_encode(apply_filters('the_content',$ tw_entry-> review_summary)); ?>'這個'<?php echo json_encode(wp_filter_nohtml_kses($ tw_entry-> review_summary)); ?>' – Noman

回答

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