4

How to check if a short wordpress $ atts is equal to something

 3 years ago
source link: https://www.codesd.com/item/how-to-check-if-a-short-wordpress-atts-is-equal-to-something.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

How to check if a short wordpress $ atts is equal to something

advertisements

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.


shortcode_atts returns an array combining the parameters passed in with the defaults you specify. So the float attribute will be stored in $atts['float']


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK