lundi 25 novembre 2019

Creating wordpress shortcode for button that is used on main site

This is the first time I am attempting to create a shortcode in Wordpress. We recreated our theme form our primary website into a custom theme for wordpress. However I am try to create a shortcode of our buttons. The HTML code looks like this:

<div class="button-group stacked-for-tiny">
<a href="#" class="button primary">Button Name</a>
<a href="#" class="button secondary">Longer Button Name</a>
<a href="#" class="button secondary">Even Longer Button Name</a>
</div>

My shortcode looks like this:

function buttonregion_shortcode( $atts , $content = null ) {

extract(shortcode_atts(
array('link' => '#', 'primary' => 'false', 'secondary' => 'true'), $atts));

if ($atts['secondary'])

return '<a class="button secondary" href="'.$link.'"><div>' . do_shortcode($content) . '</div></a>';

else
return '<a class="button primary" href="'.$link.'"><div>' . do_shortcode($content) . '</div></a>';
}
add_shortcode( 'buttonregion', 'buttonregion_shortcode' );

The buttons appear correctly but our missing the spacing between lines of text. Not sure how to incorporate class="button-group stacked-for-tiny into the mix.

Aucun commentaire:

Enregistrer un commentaire