我想使任何帖子的标题从帖子的内容。所以,我在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;
} 它在post内容中打印短代码,但是如果我应用$content = do_shortcode( $content );,它不会生成实际的post内容。当我申请$content = do_shortcode( $content );网站的时候挂掉了。让我知道如何在这个函数中使用$content = do_shortcode( $content );,以便可以更改标题。
发布于 2018-09-27 05:50:22
你能用凯斯试试这个吗?我想是你的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));https://stackoverflow.com/questions/52515635
复制相似问题