Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

i got an options page that needs to affects a certain (for now) css value..

i have about using php variables in css and creating custom global variables in wordpress but havent something easy enough to understand so i have done this and places it in my header file

<style type="text/css"> .current-menu-item { background: <?php echo get_option('sg_currentbuttoncolor'); ?> !important; } </style>

does that look like a good solution to you? what is the preffered way of creating changes in my css using values from my options page?

share|improve this question

1 Answer 1

up vote 2 down vote accepted

You are doing it correctly. I would suggest two enhancements:

  1. Do not put this code directly in header.php. Create a custom function to print the css and hook this into the wp_head action.
  2. Always sanitize/escape input before you print it to the screen. Look into ctype_xdigit() for creating a custom function to sanitize you color value.
share|improve this answer
    
Wouldn't it be more appropriate to hook this into wp_print_styles? –  tollmanz Aug 30 '11 at 1:07
    
Maybe ... but then you need to check if you're in the admin which is unnecessary IMHO. I like to follow the rule "Hook in as late as possible, but no later". wp_head fits the bill rather well and it should only fire in the front-end. –  mfields Aug 30 '11 at 1:18
    
thanks a lot @mfields :) - great advice –  Sagive SEO Aug 30 '11 at 23:38
    
You're welcome! –  mfields Sep 19 '11 at 2:14

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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