Created
October 28, 2011 10:06
-
-
Save gabrielstuff/1322013 to your computer and use it in GitHub Desktop.
Wordpress Theming by cookie
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function set_newuser_cookie() { | |
if (!isset($_COOKIE['wp_exq_cookieTheming'])) { | |
setcookie('wp_exq_cookieTheming', rand(0,5), time()+60*5, COOKIEPATH, COOKIE_DOMAIN, false); | |
} | |
} | |
add_action( 'init', 'set_newuser_cookie'); | |
/*based on some url : themes/exquiseV2/style/ */ | |
/*Style_0.css */ | |
/*Style_1.css */ | |
/*Style_2.css */ | |
/*Style_3.css */ | |
/*Style_4.css */ | |
/* Init with the custom cookie */ | |
if (isset($_COOKIE['wp_exq_cookieTheming'])) { | |
/* | |
* register with hook 'wp_print_styles' | |
*/ | |
add_action('wp_print_styles', 'add_my_stylesheet'); | |
/* | |
* Enqueue style-file, if it exists. | |
*/ | |
function add_my_stylesheet() { | |
$myStyleFile = get_template_directory().'/style/Style_'.$_COOKIE['wp_exq_cookieTheming'].'.css'; | |
if ( file_exists($myStyleFile) ) { | |
wp_register_style('myStyleSheets', $myStyleFile); | |
wp_enqueue_style( 'myStyleSheets'); | |
} | |
} | |
} | |
else { | |
/* | |
* register with hook 'wp_print_styles' | |
*/ | |
add_action('wp_print_styles', 'add_my_stylesheet'); | |
/* | |
* Enqueue style-file, if it exists. | |
*/ | |
function add_my_stylesheet() { | |
$myStyleFile = get_template_directory().'/style/Style_'.rand(0,5).'.css'; | |
if ( file_exists($myStyleFile) ) { | |
wp_register_style('myStyleSheets', $myStyleFile); | |
wp_enqueue_style( 'myStyleSheets'); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment