If you want to pass boolean value in shortcode in WordPress? Is easy to use 0
and 1
values and then typecasting inside the function:
[shortcode boolean_attribute='1']
or [shortcode boolean_attribute='0']
but if you want you can also strictly check for 'false'
and assign it to boolean, in this way you can also use:
[shortcode boolean_attribute='false']
or [shortcode boolean_attribute='true']
1 2 3 4 5 6 7 8 9 | add_shortcode( 'shortcode', 'shortcode_cb' ); function shortcode_cb( $atts ) { extract( shortcode_atts( array( 'boolean_attribute' => 1 ), $atts ) ); if ( $boolean_attribute === 'false' ) $boolean_attribute = false; $boolean_attribute = (bool) $boolean_attribute; } |
If you like this question & answer and want to contribute, then write your question & answer and email to freewebmentor[@]gmail.com. Your question and answer will appear on FreeWebMentor.com and help other developers.