首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Wordpress do_shortcode()与post_content

Wordpress do_shortcode()与post_content
EN

Stack Overflow用户
提问于 2018-09-26 10:30:43
回答 1查看 1.3K关注 0票数 0

我想使任何帖子的标题从帖子的内容。所以,我在functions.php中做了以下的事情

代码语言:javascript
复制
 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 );,以便可以更改标题。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-09-27 05:50:22

你能用凯斯试试这个吗?我想是你的html o/p引起了这个问题。

代码语言:javascript
复制
$content = $post->post_content;
$content = wp_filter_nohtml_kses( $content ); // this wp_filter_nohtml_kses indicates strip_tags
$content = do_shortcode( $content );

代码语言:javascript
复制
echo do_shortcode(get_post_field('post_content', $post->id));
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/52515635

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档