I commented under another thread and couldn’t get any reply, so I’m creating a new thread. I’m pasting my previous post:
I was using a javascript style switcher to change the backgrounds and it was working. Then I tried to change top navigation’s background color independent of body background, but whenever I change either of them the other one falls back to default. (ie I can’t view the alternative background with alternative navigation color) And I decided to try this php method. I pasted this code to my header.php:
<?php if(isset($_GET['color'])) { $color = $_GET['color']; setcookie('color', $color); }?>
<?php if(isset($_GET['color']))
{
$color = $_GET['color'];
}
else
{
if(isset($_COOKIE['color']))
{
$color = $_COOKIE['color'];
}
else
{
$color = get_option('color');
}
}
?>
<link href="<?php bloginfo( 'template_url' ); ?>/css/<?php echo $color; ?>" rel="stylesheet" media="all" type="text/css" />
and created a list like:
<ul>
<li><a href="<?php bloginfo('url'); ?>/?color=blue">Blue</a></li>
<li><a href="<?php bloginfo('url'); ?>/?color=orange">Orange</a></li>
</ul>
(and I have the css files under a css folder named blue.css etc) But I get the error:
Warning: Cannot modify header information – headers already sent by (output started at …/header.php:5) in …/header.php on line 13
(And I’m trying all of this @ local host just to inform) I guess if I manage to do this, I’ll be able to change different elements’ styles independently. Anyone can help?
- Author had a Free File of the Month
- Author was Featured
- Bought between 10 and 49 items
- Egypt
- Exclusive Author
- Has been a member for 2-3 years
- Item was Featured
- Referred between 10 and 49 users
- Sold between 10 000 and 50 000 dollars
I optimised the code above just few, you dont need get_option('color'); in here as you can just add ?color=blue at the end of the demo url here on themeforest
if(isset($_GET['color'])) {
$color = $_GET['color'];
if(!isset($_COOKIE['color'])) {
setcookie('color', $color);
} else {
$color = $_COOKIE['color'];
}
} else {
$color = get_option('color');
}
<link href="<?php bloginfo('template_directory'); ?>/css/<?php echo $color; ?>.css" rel="stylesheet" type="text/css" media="all" />
I optimised the code above just few, you dont needget_option('color');in here as you can just add?color=blueat the end of the demo url here on themeforestif(isset($_GET['color'])) { $color = $_GET['color']; if(!isset($_COOKIE['color'])) { setcookie('color', $color); } else { $color = $_COOKIE['color']; } } else { $color = get_option('color'); } <link href="<?php bloginfo('template_directory'); ?>/css/<?php echo $color; ?>.css" rel="stylesheet" type="text/css" media="all" />
Thanks so much wizy labs, I tested it and it works! But it keeps giving that error (Warning: Cannot modify header information – headers already sent by (output started at …/header.php:5) in …/header.php on line 13 ) Do you think I see this error because I’m testing it on localhost?
- Author had a File in an Envato Bundle
- Author had a Free File of the Month
- Author was Featured
- Bought between 100 and 499 items
- Europe
- Exclusive Author
- Featured in a Magazine
- Has been a member for 3-4 years
You probably have some whitespace in front of <?php
Make sure you remove all spaces 
No, I don’t have any whitespace there. And the code at the line that eror message points is:
setcookie('Color',$Color);
I basically have no idea..
- Author had a File in an Envato Bundle
- Author had a Free File of the Month
- Author was Featured
- Bought between 100 and 499 items
- Europe
- Exclusive Author
- Featured in a Magazine
- Has been a member for 3-4 years
Try to put in the very first line <?php session_start() ?>. And I really recommend you to use sessions instead of cookies.
I for example have disabled cookies by default and only activate them on “trusted” sites. Sessions aren’t saved on the users computer, they are stored on the server.
I put the <?php session_start() ?> code at the top of my header.php , it didn’t work. But can you pls paste the code to use sessions to change color? Thanks so much for your replies Bebel 
- Author had a Free File of the Month
- Author was Featured
- Bought between 10 and 49 items
- Egypt
- Exclusive Author
- Has been a member for 2-3 years
- Item was Featured
- Referred between 10 and 49 users
- Sold between 10 000 and 50 000 dollars
Hi,
Place <?php session_start() ?> at the top of functions.php file then in your header.php use the code below
<?php $_SESSION['color'] = 'blue';
if(isset($_GET['color']))
$_SESSION['color'] = $_GET['color'];
?>
<link href="<?php bloginfo('template_directory'); ?>/css/<?php echo $_SESSION['color']; ?>.css" rel="stylesheet" media="all" type="text/css" />
I couldn’t get it worked with sessions but I realized that I can make that error disappear by putting taking the cookies method code between <!-- and --> tags lol I got it working somehow with your help, you guys are awesome, thak you very much ! :))
Update: I’ve got session method working!! Thank you soooo much Wizylabs! 
