如何在Wordpress HTML中剥离短代码



>我有一个自定义主题,当我上传带有标题的图像时,标题短代码会显示在页面上:[caption id="attachment_109"]....使用WP的默认主题之一,我认为没有问题。在检查时,WP使用the_content(),链接,所以我需要做一些剥离。我得到我的帖子与get_page_by_path()

<?php
$post = get_page_by_path( $current_page->post_name, OBJECT, 'service' );
// I assume this would work
$content = the_content($post->post_content);
//Blank page:
echo $content;

回显$post->post_content显示如上所述的字幕短代码。如果它如何摆脱?顺便说一句,我需要标题值。

你可以像这样获取帖子内容

$post = get_post(123);  //pass the id of the post
$content = $post->post_content;
$content = apply_filters('the_content', $content);
$content = str_replace(']]>', ']]&gt;', $content);
echo $content;

$content=apply_filters('the_content', get_post_field('post_content', 123)); //123 is the post id

之后,只需剥离简码,您还可以通过has_shortcode检查帖子中是否有简码

最新更新