我有一个自定义主题,当我上传带有标题的图片时,标题短代码显示在页面上:[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
显示如上所述的字幕短代码。怎么摆脱它?顺便说一句,我需要标题值。
答案 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(']]>', ']]>', $content);
echo $content;
或
$content=apply_filters('the_content', get_post_field('post_content', 123)); //123 is the post id
之后只需删除短代码,您也可以has_shortcode