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

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
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


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.