您可以使用init 设置cookie的操作,以及读取cookie的其他init操作。然而,由于它是一块饼干。。。您还需要检查GET变量。
add_action(\'init\', \'is_it_mobile_or_desktop\', 1);
function is_it_mobile_or_desktop(){
if (isset($_GET[\'site\']) && in_array($_GET[\'site\'], array(\'mobile\', \'desktop\')) ) {
setcookie( \'site\', $_GET[\'site\'], time() - YEAR_IN_SECONDS, SITECOOKIEPATH, COOKIE_DOMAIN );
}
}
add_action(\'init\', \'who_am_i\', 2);
function who_am_i(){
$site = isset($_GET[\'site\']) && in_array($_GET[\'site\'], array(\'mobile\', \'desktop\')) ? $_GET[\'site\']
: (isset($_COOKIE[\'site\']) && in_array($_COOKIE[\'site\'], array(\'mobile\', \'desktop\')) ? $_COOKIE[\'site\'] : \'default_case\');
if ($site == \'mobile\'){
function responsive_css(){
wp_enqueue_style(
\'wpa_custom\',
get_template_directory_uri() . \'/css/responsive.css\'
);
}
add_action( \'wp_enqueue_scripts\', \'responsive_css\', 999 );
} else {
function default_css(){
wp_enqueue_style(
\'default_css\',
get_template_directory_uri() . \'/style.css\'
);
}
add_action( \'wp_enqueue_scripts\', \'default_css\', 999 );
}
}