Wordpress/PHP - load stylesheet when URL parameter is present -


hoping find way make wordpress site load stylesheet when url parameter present. example when http://www.somesite.com loaded, use whatever stylesheets in use theme. if specific url parameter used, additional stylesheet called. example http://www.somesite.com?usealtcss=yes. in case, additional stylesheet loaded after theme stylsheets. gives me opportunity override theme styles when url parameter used, , test style/laylout changes without effecting public viewing.

i assume coding modification needed header.php. following not working php syntax gives idea of i'm looking for:

<?php     $param = ($_get["usealtcss"]);     if($param == 'yes') {         <link rel="stylesheet" type="text/css" href="custom.css" />     } else {         // nothing     } ?> 

update:

looks original code close had change line 4 from:

<link rel="stylesheet" type="text/css" href="custom.css" /> 

to:

echo('<link rel="stylesheet" type="text/css" href="custom.css" />'); 

while working, im wondering if there more efficient way of doing this. if navigate new page test style changes, have manually add url parameter. great if somehow locked in custom.css stylsheet... maybe using cookie or session? wonder how toggled on/off. thoughts?

if you're using think method fine... - else stumbling upon question - want emphasize not doing things book. second method suggested below ok solution, first should used temporary situation (opening session on each page load unnecessary , cause performance degradation).

stylesheets shouldn't printed manually (ie. using <link[...]>), instead use wp_enqueue_style() in wp_enqueue_scripts hook.

method 1

to keep "setting" instead of having manually type on every page load can use session this:

you need open session before headers sent, put in wp-config.php:

//start session if isn't session_start(); 

the rest goes wherever want stylesheet (most in header.php):

//check if parameter set if (isset($_get["usealtcss"])) {     if($_get["usealtcss"] === 'yes') {         //adjust session         $_session['usealtcss'] = true;     } else {         /**          * if set other "yes", assume it's being switched          * off, , adjust session          */         $_session['usealtcss'] = false;     } } //check if session variable exists, , true if (isset($_session['usealtcss']) && $_session['usealtcss'] === true) {     //and print stylesheet     echo '<link rel="stylesheet" type="text/css" href="custom.css" />'; } 

method 2

another (simpler) option check if current user logged in , has capability edit theme (which expect do):

if (current_user_can('edit_themes')) {     echo '<link rel="stylesheet" type="text/css" href="custom.css" />'; } 

...this of course won't allow switch , forth - except logging in , out each time.


Comments