0

I'm developing a WordPress theme with some theme options (using the ThemeShaper sample theme options page), and one of the options I want is to allow users to set their own link colours.

At the moment I can get the hex value they set (say #134679 or something) and spit it out somewhere, but I don't know how to include it in the theme.

Presumably it needs to be dynamically added to a stylesheet (or a new stylesheet dynamically generated?) or something like that, in order to then be linked to from the theme's pages and all start to work. If so, how is this done? And what's the 'best' way to do it?

Thanks.

Edit: I'm not a PHP person, at all, so... layman's language, please. :)

1 Answer 1

1

To make theme options for css, you include the css in the header. on wp_head...

For instance, I have set up various options in my admin menu in an array.

        'name' => __( 'Custom CSS', 'voodoo_lion' ),   
    "desc" => __( 'Want to add any custom CSS code? Put in here, and the rest is taken care of. This overrides any other stylesheets. eg: a.button{color:green}', 'voodoo_lion' ),   
    "id" => $shortname."_custom_css",   
    "type" => "textarea",   
    "std" => ""
),

is the option for entering custom css. Then I add that action to wp_head

add_action( 'wp_head', 'voodoo_inline_css', 100000 );

and define voodoo_inline_css. I have a variety of things in the voodoo_inline_css function, but one of them is:

if( get_theme_option( 'custom_css' ) ) 
    theme_option( 'custom_css' );

Hopefully that helped a little... you can also just call the option directly in header.php

<style type="text/css" media="screen">
   .content a:link {
        color: <?php echo get_theme_option(' link-color '); ?>;
    }
</style>

Either way, you need to output the css into the header rather than trying to get it into a stylesheet.

Just a note here, this theme options code is copy/pasted from my theme as an example so you can see bits of code and compare. Since you followed your own tutorial, your options will be set up somewhat differently. I wanted to show that you would output your option to the header (using either wp_head or directly) to have the css take effect.

6
  • Just a reminder Rev. Vooddo, those theme option functions won't work for anyone else, i wrote those specifically for your theme... ;)
    – t31os
    Commented Mar 8, 2011 at 16:16
  • Yeah, he already had a custom theme option set up through his tutorial.... I was more trying to explain (albeit in a roundabout way) that he had to output whatever his options were into the header.... Probably should have been more clear on that part... Thanks! Commented Mar 8, 2011 at 16:36
  • Still pretty confused, I'm afraid. When you say you add the action to wp_head, what does that mean? Do you add it in functions.php? Like I said, I'm not a PHP person.
    – snthr
    Commented Mar 8, 2011 at 17:18
  • yeah, add action would go in functions.php. For one single option you may be best just adding your option directly to your header.php. You said you already know how to take the option value and spit it out somewhere. So my last bit of code would work best for you really, just swapping out my php code for whatever you use to spit out the values. That last bit of code would go in header.php inside the <head> section Commented Mar 8, 2011 at 18:00
  • But the best-practice way of doing this would be through using wp_head, right?
    – snthr
    Commented Mar 8, 2011 at 21:36

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.