WordPress的do_shortcode()与post_content

时间:2018-09-26 10:30:43

标签: wordpress

我想用帖子内容作为帖子的标题。因此,我在functions.php中做了以下内容

 function my_title($title)   
 {  
    global $post;       
    // Do whatever here with your title...  
    $content = $post->post_content;
    print $content;       

    $title =$content.  $post->post_title . ' | ' .  
    get_bloginfo('name');     

    return $title;  
}  

它在帖子内容内打印简码,但如果我应用$content = do_shortcode( $content );,则不会生成实际的帖子内容。当我应用$content = do_shortcode( $content );网站时挂起。让我知道如何在此函数内使用$content = do_shortcode( $content );,以便可以更改标题。

1 个答案:

答案 0 :(得分:1)

您可以使用wp_filter_nohtml_kses尝试此操作吗?我想您的html o / p引起了问题

$content = $post->post_content;
$content = wp_filter_nohtml_kses( $content ); // this wp_filter_nohtml_kses indicates strip_tags
$content = do_shortcode( $content );

echo do_shortcode(get_post_field('post_content', $post->id));