0

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?

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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