欢迎光临
我们一直在努力

本站Quench主题文章不分段的解决办法

本站使用的是免费的Quench主题,使用过程中,突然发现在后台发布文章的时候用回车进行段落划分,但是到前台显示的时候整篇文章就是一整段。经百度查找WordPress 有个自动分段机制,只要你在可视化下敲击一次回车(文本模式敲击两次回车),就会在前台html自动添加分段标签<p>,这个自动分段机制,使用的是 wpautop() 函数,只会对文章内容和摘要生效。

如果你希望禁用它,可以将下面的代码添加到主题的 functions.php 文件即可:

[cc lang="php"]
remove_filter( 'the_content', 'wpautop' ); //正文
remove_filter( 'the_excerpt', 'wpautop' ); //摘要
[/cc]

经查,在主题的函数文件34行果然有这段代码,把移除正文的那部分用//注释掉,刷新后,文章分段正常了。

关于这两个函数的扩展应用,通过构建函数,指定类型文章去除自动分段功能。

在 functions.php 添加函数

[cc lang="php"]
function needRemoveP() {
remove_filter('the_content', 'wpautop');
}
[/cc]

然后在你想去掉功能的地方,比如想让文章去掉这个默认的功能,则在single.php里添加:

[cc lang="php"]

[/cc]

还有更加方便的方法,不需要修改 single.php 文件,而是通过条件标签来判断,在主题 functions.php 使用下面的代码:

[cc lang="php"]
function needRemoveP() {
if ( get_post_type() == 'post'){ // 如果文章类型为 post
remove_filter('the_content', 'wpautop');
}
}
add_action ('loop_start', 'needRemoveP');
[/cc]

以上代码的第 2 行就限定了文章类型为 post 的文章才会取消自动分段,你可以根据自己的需要修改文章类型。

分享到: 更多 (0)

点击此处获取更多金融后续培训参考答案

相关推荐

  • WordPress优化评论,防止灌水解决办法-侯建方的个人网站WordPress优化评论,防止灌水解决办法
  • WordPress播放器插件,支持HTML5-侯建方的个人网站WordPress播放器插件,支持HTML5

  • Notice: Undefined index: taxonomy in /data/wwwroot/houjianfang.com/wp-content/plugins/wpjam-basic/public/wpjam-thumbnail.php on line 84

    Notice: Undefined index: post_meta in /data/wwwroot/houjianfang.com/wp-content/plugins/wpjam-basic/public/wpjam-thumbnail.php on line 78

    Notice: Undefined index: taxonomy in /data/wwwroot/houjianfang.com/wp-content/plugins/wpjam-basic/public/wpjam-thumbnail.php on line 84

    Notice: Undefined index: post_meta in /data/wwwroot/houjianfang.com/wp-content/plugins/wpjam-basic/public/wpjam-thumbnail.php on line 78
    几篇关于Wordpress的文章-侯建方的个人网站几篇关于Wordpress的文章
  • wordpress评论标注作者-侯建方的个人网站wordpress评论标注作者

  • Notice: Undefined index: taxonomy in /data/wwwroot/houjianfang.com/wp-content/plugins/wpjam-basic/public/wpjam-thumbnail.php on line 84

    Notice: Undefined index: post_meta in /data/wwwroot/houjianfang.com/wp-content/plugins/wpjam-basic/public/wpjam-thumbnail.php on line 78

    Notice: Undefined index: taxonomy in /data/wwwroot/houjianfang.com/wp-content/plugins/wpjam-basic/public/wpjam-thumbnail.php on line 84

    Notice: Undefined index: post_meta in /data/wwwroot/houjianfang.com/wp-content/plugins/wpjam-basic/public/wpjam-thumbnail.php on line 78
    网站安装新插件-侯建方的个人网站网站安装新插件

  • Notice: Undefined index: taxonomy in /data/wwwroot/houjianfang.com/wp-content/plugins/wpjam-basic/public/wpjam-thumbnail.php on line 84

    Notice: Undefined index: post_meta in /data/wwwroot/houjianfang.com/wp-content/plugins/wpjam-basic/public/wpjam-thumbnail.php on line 78

    Notice: Undefined index: taxonomy in /data/wwwroot/houjianfang.com/wp-content/plugins/wpjam-basic/public/wpjam-thumbnail.php on line 84

    Notice: Undefined index: post_meta in /data/wwwroot/houjianfang.com/wp-content/plugins/wpjam-basic/public/wpjam-thumbnail.php on line 78
    新浪SAE安装最新wordpress解决附件无法上传的问题-侯建方的个人网站新浪SAE安装最新wordpress解决附件无法上传的问题

  • Notice: Undefined index: taxonomy in /data/wwwroot/houjianfang.com/wp-content/plugins/wpjam-basic/public/wpjam-thumbnail.php on line 84

    Notice: Undefined index: post_meta in /data/wwwroot/houjianfang.com/wp-content/plugins/wpjam-basic/public/wpjam-thumbnail.php on line 78

    Notice: Undefined index: taxonomy in /data/wwwroot/houjianfang.com/wp-content/plugins/wpjam-basic/public/wpjam-thumbnail.php on line 84

    Notice: Undefined index: post_meta in /data/wwwroot/houjianfang.com/wp-content/plugins/wpjam-basic/public/wpjam-thumbnail.php on line 78
    修改主题自带的短代码-侯建方的个人网站修改主题自带的短代码

  • Notice: Undefined index: taxonomy in /data/wwwroot/houjianfang.com/wp-content/plugins/wpjam-basic/public/wpjam-thumbnail.php on line 84

    Notice: Undefined index: post_meta in /data/wwwroot/houjianfang.com/wp-content/plugins/wpjam-basic/public/wpjam-thumbnail.php on line 78

    Notice: Undefined index: taxonomy in /data/wwwroot/houjianfang.com/wp-content/plugins/wpjam-basic/public/wpjam-thumbnail.php on line 84

    Notice: Undefined index: post_meta in /data/wwwroot/houjianfang.com/wp-content/plugins/wpjam-basic/public/wpjam-thumbnail.php on line 78
    wordpress英文主题截取中文不显示-侯建方的个人网站wordpress英文主题截取中文不显示