首页 > 新闻资讯 > 怎样不修改模板文件而移除WordPress主页上的Widget?

怎样不修改模板文件而移除WordPress主页上的Widget?

2条评论
标签:
更多

如果不想让主页显示Widget,又不想改动模板文件,怎么办?很简单,把下面的代码添加到functions.php文件中:

<?php
add_filter( 'sidebars_widgets', 'disable_all_widgets' );
function disable_all_widgets( $sidebars_widgets ) {
    if ( is_home() )
        $sidebars_widgets = array( false );
    return $sidebars_widgets;
}
?>

大功告成!

原文:How to: Remove widget areas on your blog homepage without editing template files

* 版权声明:作者WordPress啦! 转载请注明出处。

#1
汗,这样不叫修改模板文件?...
#2
可能作者的意思是不修改“用作显示的模版文件”吧

发表新评论

此内容将保密,不会被其他人看见。
  • 自动将网址与电子邮件地址转变为链接。
  • 允许HTML标签:<a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • 自动断行和分段。

更多关於格式化选项的信息

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
Image CAPTCHA
Enter the characters shown in the image.