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;
}
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”
As I undertand the “add_filter()” should be a function that is built in wordpress.
As Dawson said, this needs to go in your
/wp-content/themes/[theme]/functions.php
file.In wordpress root directory, put
require( ABSPATH . WPINC . '/plugin.php' );
beforerequire( 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.