如何在Wordpress HTML中删除短代码

时间:2017-07-21 11:53:10

标签: php wordpress

我有一个自定义主题,当我上传带有标题的图片时,标题短代码显示在页面上:[caption id="attachment_109"]...。使用WP的默认主题之一,我认为没有问题。在检查时,WP使用the_content()link,因此我需要进行一些剥离。我的帖子有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显示如上所述的字幕短代码。怎么摆脱它?顺便说一句,我需要标题值。

1 个答案:

答案 0 :(得分:3)

您可以获得这样的帖子内容

$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

检查帖子中是否包含短代码
相关问题