Possible noob question -- please be nice.

I'm doing up a theme options page using the sample from Themeshaper, and one of the options I want to have is to set the width of the sidebar.

To do this with the CSS I already have, I need to change class attributes in my HTML in two places (one for the main column width, one for the sidebar).

The Themeshaper code is fine for adding little theme option tweaks, but I can't figure out how to get a single option to modify two places in the code at once.

Possibly (hopefully!) a simple question, but beyond my current abilities.

Any help greatly appreciated. Thanks.


I should clarify that I'm not a programmer, and I'm already waaay out of my depth. That said, here's what I'm going for... In my theme options page, I want to have a drop-down menu with two options: 'wide sidebar' and 'narrow sidebar'. One of these will be the default. Changing the default needs to modify two CSS classes. I appreciate Rarst's answer below but I simply don't know enough about PHP to be able to get it to work. Is there a simple(r) explanation for how to get this to happen? Again, sorry if this is basic stuff.

  • This is kinda hard to explain without programming because it essentially is programming. :) Had you got example code you linked to working? Do you understand it enough to add your own options or not even that?
    – Rarst
    Jan 23, 2011 at 16:31
  • Hi Rarst, thanks again. I have the example code working, sort of, in that I can echo out a value in index.php (or wherever) once it's set in the theme options, but that's it. I understand enough to add options to the theme options page, but not enough PHP knowledge to 'play' with this stuff once it comes through. Maybe someone here could point me to a good online tutorial for this kind of thing, but if not, then I'm still a bit stuck.
    – snthr
    Jan 23, 2011 at 17:32

1 Answer 1


Nothing prevents you from retrieving your option in several places. You can do several get_option() calls or create global variable and assign your value to it once.

It is hard to come up with specific example without knowing what exactly you store in option and which classes you want to generate for your markup.


One of the ways to get it done. Depending on how you organize code you might need to declare variables as global :

$options = get_option('sample_theme_options');
$sidebar_width = $options['sidebar_width']; // let's say we have stored integer '2' here
$column_width = 8 - $sidebar_width; // total width minus sidebar

// and then in template
echo "<div class='main-{$column_width}col'> main </div>";
echo "<div class='sidebar-{$sidebar_width}col'> sidebar </div>";
  • Well, i'm using an eight-column-wide grid-based CSS layout, so I need to simultaneously change two classes. Something like this: <div class="main-6col"> main </div> <div class="sidebar-2col"> sidebar </div> ...where i need to change it to 'main-5col' and 'sidebar-3col' at the same time. Does that make sense?
    – snthr
    Jan 22, 2011 at 17:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.