You can use init action to set cookie, and other init action to read it. However due its a cookie… you will need also to check GET variable.
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 );
}
}