Simple shortcode function :
function my_shortcode_function($atts,$content=null){
// Do something
return $content;
}
add_shortcode('my_shortcode','my_shortcode_function');
I wonder how to add more extra body class when user use this shortcode in contents.
I can't do something like :
function my_shortcode_function($atts,$content=null){
// Do something
add_filter('body_class','my_body_class');
return $content;
}
function my_body_class($classes) {
$classes[] = 'foo';
return $classes;
}
add_shortcode('my_shortcode','my_shortcode_function');
Any idea ?
body_class()
has run. You could "sniff" for your shortcode beforeget_header()
, but have you considered another option as opposed to needing an extra body class? What is your ultimate goal?has_shortcode
insidebody_class
filter