致命错误:在Wordpress中调用index.php中未定义的函数add_filter() [英] Fatal error: Call to undefined function add_filter() in index.php in Wordpress

查看:167
本文介绍了致命错误:在Wordpress中调用index.php中未定义的函数add_filter()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想通过用户浏览器动态更改我的wordpress主题.所以我在网上找到了这段代码并将其添加到我的index.php文件中

I want to change my wordpress theme dynamically by user browser. So I found this code on the net and added it to my index.php file

add_filter('template', 'switch_theme_by_browser');
add_filter('stylesheet', 'switch_theme_by_browser');

function switch_theme_by_browser($theme) {

    $browser = $_SERVER['HTTP_USER_AGENT'];

    if(preg_match('/MSIE/i',$browser) && !preg_match('/Opera/i',$browser))
    {
        $theme = "twentyeleven";
    }
    elseif(preg_match('/Firefox/i',$browser))
    {
        $theme = "twentyten";
    }
    elseif(preg_match('/Chrome/i',$browser))
    {
        $theme = "Boxoffice";
    }

    return $theme;
}

之后,它显示致命错误:在第17行的/home/xxx/public_html/domain.com/index.php中调用未定义的函数add_filter()"

After that it shows me "Fatal error: Call to undefined function add_filter() in /home/xxx/public_html/domain.com/index.php on line 17"

正如我所理解的那样,"add_filter()"应该是在wordpress中内置的函数.

As I undertand the "add_filter()" should be a function that is built in wordpress.

推荐答案

在wordpress根目录中,将wc-settings.php文件中的require( ABSPATH . WPINC . '/plugin.php' );放在require( ABSPATH . WPINC . '/functions.php' );之前. 我在 http://wordpress.org/上验证了此解决方案support/topic/fatal-error-call-to-undefined-function-add_filter .

In wordpress root directory, put require( ABSPATH . WPINC . '/plugin.php' ); before require( ABSPATH . WPINC . '/functions.php' ); in file wp-settings.php. I verified this solution at http://wordpress.org/support/topic/fatal-error-call-to-undefined-function-add_filter.

这篇关于致命错误:在Wordpress中调用index.php中未定义的函数add_filter()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆