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.

The function below creates a button when used like so [btn]Button Text[/btn]

function btn($atts, $content = null) {
   extract(shortcode_atts(array('link' => '#'), $atts));
   return '<a class="btn" href="'.$link.'"><span>' . do_shortcode($content) . '</span></a>';
}

I'd like to be able to add two variations to this, color and size which would allow the button to be called with variations, like this: [button color="teal" size="large"]Button Text[/button]

But I can't figure out how to do this. Anybody have a code?

share|improve this question

1 Answer 1

up vote 0 down vote accepted
function btn($atts, $content = null) {
   extract(shortcode_atts(array('link' => '#', 'color' => 'teal' , 'size' => 'large'), $atts));
   return '<a class="btn '.$size.'" href="'.$link.'" style="background:'.$color.';"><span>' . do_shortcode($content) . '</span></a>';
}

With that function you get by default color teal and size large. I suppose that for size you are using classess and for color just background. If not the case just leave a space and added it on the class attribute.

share|improve this answer

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.