WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm developing a theme where I'm using theme options to allow users to set various things -- text size, background colour, link colour, etc.

The basic code I'm using for the options is in header.php and looks like this:

$options = get_option('mytheme_theme_options');

if( isset( $options['backgroundcolour'] ) && ( !empty( $options['backgroundcolour'] ) ) )   
printf( "body {background: #%s;}", $options['backgroundcolour'] );

if( isset( $options['linkcolour'] ) && ( !empty( $options['linkcolour'] ) ) )   
printf( "a, a:link {color: #%s;}", $options['linkcolour'] );


One of the options I want to set is a border radius for some chunks of content, which requires multiple declarations of the same value to work in all modern browsers:

.post {-webkit-border-radius: 8px; -moz-border-radius: 8px; border-radius: 8px;}

So, how do I get the PHP above to declare the same value three times in my CSS?

I should add that I'm not normally a PHP person; feeling a bit out of my depth here. :)


share|improve this question
up vote 1 down vote accepted

Use standard echo or printf with additional parameters. e.g.

if(isset($option['borderradius']) && (!empty($option['borderradius']))) {   
    $borderradius = '.post { ';
    $borderradius .= 'border-radius: ' . $option['borderradius'] . 'px; ';
    $borderradius .= '-webkit-border-radius: ' . $option['borderradius'] . 'px; ';
    $borderradius .= '-moz-border-radius: ' . $option['borderradius'] . 'px; ';
    $borderradius .= '}';

    echo $borderradius;

if(isset($option['borderradius']) && (!empty($option['borderradius']))) { 
    printf('.post { border-radius: %spx; -webkit-border-radius: %spx; -moz-border-radius: %spx; }', $option['borderradius'], $option['borderradius'], $option['borderradius']);
share|improve this answer
Hi Roman... Thanks for the reply, I'll try it out tomorrow and see if it works. Do you know, though, if there is any simpler/smaller way of getting the same result? I thought that it might be do-able with less code. – snthr May 3 '11 at 20:55
The second part only requires 3 lines of code. It's really basic php, so may answer here is no. Maybe you want to checkout the PHP tutorial of Quakenet if need more help on PHP. – rofflox May 4 '11 at 9:45
Hi Roman... Thanks, I hadn't realised that you'd given me two different ways to do the same thing, I thought it was all one big lump of code. :) I went with the second way, worked great. Thanks! – snthr May 4 '11 at 10:13

Your Answer


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.