I am trying yo understand this function, as a preface to forking it to make similar functions for my own shortcodes. I understand how to define shortcodes and their functions. I also basically "get" what the original author is doing here: collecting parameters from the shortcode and assembling them into an HTML tag and returning that tag. It seems the order of the params is unimportant, but their names are.
However, when I am working with this code, it does not seem to understand which param is which. For example, the original docs say to use the shortcode like so:
[button link="http://google.com" color="black" size="small"]Button Text[/button]
But when I use this shortcode, I get:
<a href="Button Text" title="Array" class="button button-small button " target="_self">
<span>Array</span>
</a>
Here's my PHP:
if( ! function_exists( 'make_button' ) ) {
function make_button( $text, $url, $color = 'default', $target = '_self', $size = 'small', $classes = null, $title = null ) {
if( $target == 'lightbox' ) {
$lightbox = ' rel="lightbox"';
$target = null;
} else {
$lightbox = null;
$target = ' target="'.$target.'"';
}
if( ! $title )
$title = $text;
$output = '<a href="'.$url.'" title="'.$title.'" class="button button-'.$size.' '.$color.' '.$classes.'"'.$target.$lightbox.'>';
$output .= '<span>'.$text.'</span>';
$output .= '</a>';
return $output;
}
}
add_shortcode( 'button', 'make_button' );