I have different menu items. When the user clicks on a menu item, I want them to go to a particular destination. Each menu’s destination has a different background color.
I’m thinking that I can pass a variable around and based on the value, I can set the bgcolor.
This is just one example of why I want to pass data around.
Does WordPress have anything built in that allows me to do this? Should I use session variables?
When you say destination I assume you mean page or post. If you use WordPress’s built in body class and post class you can target the page or post in your CSS and assign a different background color for each.
How to use WordPress body class:
In header.php add body_class() between the body tags and WordPress will assign a different class to each page. The body tag:
This will output your body tag in html like so:
To assign the background color in css:
Then you would just repeat the above for each page that needs a different background color.
How to use WordPress post class:
In your template file that is displaying the post, single.php or index.php add the following in the loop:
This will output your html like so:
Use CSS to target the post just like we did the body using any of the outputted class or ids
WordPress doesn’t use session variables … so you might run into problems if you try that approach. From your description, though, I’d suggest adding a variable via the URL’s query string. You can use WordPress permalinks system to do this, or merely add “?bg=123” to the end of the URL. Then use that variable to determine which background color to use.