2012-11-07 4 views
0

사용자 브라우저에서 WordPress 테마를 동적으로 변경하고 싶습니다. 그래서 그물에이 코드를 발견하고치명적인 오류 : Wordpress의 index.php에서 정의되지 않은 함수 add_filter()를 호출하십시오.

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; 
} 

그것은 나를 보여줍니다 그 후 내 index.php 파일에 추가 "치명적인 오류 :/홈/XXX/public_html을/도메인에 정의되지 않은 함수 add_filter()를 호출합니다. com/index.php on line 17 "

"add_filter() "는 wordpress에 내장 된 함수 여야합니다.

+1

index.php 대신 functions.php를 추가하십시오. –

+0

문제는로드하는 템플릿을 알 수 있도록 사이트에서 가장 먼저 읽어야하는 것입니다. –

답변

0

Dawson이 말했듯이이 파일은 /wp-content/themes/[theme]/functions.php 파일에 있어야합니다.

+0

이제 알았습니다 : 경고 : 필요 (/home/xxx/public_html/domain.net/wp-content/themes/twentyten/inc/theme-options.php) [function.require] : 스트림을 열지 못했습니다 : 아니요 그러한 파일 또는 디렉토리 /home/xxx/public_html/domain.net/wp-content/themes/twentyeleven/functions.php 온라인 122 치명적인 오류 : require() [function.require] : 실패한 열 필요 '/ home/include/path/'/ usr/lib/php :/usr/local/lib/php')/home/xxx/public_html/domain.net/wp-content/themes/twentyeleven/functions.php on line 122 –

관련 문제