Though my problem is probably quite simple, I did not find a previous post that really matches, but please apologize if I’ve missed something.
I want to read a cookie and load a stylesheet according to the value. It’s a styleswitcher I made myself some time ago, I already have a bunch of stylesheets that create completely different layouts while the html code is always the same. If it is possible, I wish to keep it and not use another style or theme switcher.
It worked fine with WP 1.2.2. I created the html markup I needed via the index.php and wp-comments.php. In the part that creates the header in the index.php, I checked if there is a cookie and loaded the according css file. If there was no cookie, the default css file was loaded.
It should work with WP 184.108.40.206 too. I already made a theme that generates the html markup I need, no problem with that. But unfortunately WP seems not to read the cookie. The cookie is there and the value too, it’s set by a php script outside WP via a form where the user can choose the layout. Pages outside WP just do what I want them to do, they load the css file according to the cookie, but all WP pages just load the default css file as if there was no cookie.
Here is the code I inserted in the header template where you usually load the theme’s css file, $stylename is the variable in the cookie:
echo "\t<link rel=\"stylesheet\" type=\"text/css\" href=\"default.css\" />\n";
echo "\t<link rel=\"stylesheet\" type=\"text/css\" media=\"screen\" href=\"style1.css\" />\n";
echo "\t<link rel=\"stylesheet\" type=\"text/css\" media=\"screen\" href=\"style2.css\" />\n";
Any idea why this does not work?
Could you tell me if you got this figured out? It turns out I’m trying to do exactly the same thing — and am having the same problem. 🙂
- The topic ‘Read cookie in header template?’ is closed to new replies.