I am trying to figure out how to figure out how to check to see if a shortcode attribute is equal something and than if it is set a variable.
I have an image shortcode with an attribute of float and I want to set a class to float right if the user enters in float="right" as an attribute but if not than do nothing.
add_shortcode( 'img', 'img_shortcode' );
function img_shortcode( $atts, $content = null ) {
$atts = shortcode_atts(
array(
'float' =>'',
), $atts);
$ImgFloat = '';
if(float attribute = right){
$ImgFloat = 'class="img-right"';
}
return '
<div class="img-shortcode">
<img '. $ImgFloat .' src="'. $content .'" />
</div>
';
}
Above is the shortcode, as you can see the If statement is where I'm having the trouble, I would like to figure out how to check to see if the attribute float is set to anything if it is set to right, than make $imgFloat variable equal to the float right class that I have set.