838 posts
  • Power Elite Author: Sold more than $1M on Envato Market
  • Won a competition
  • Became a Top 20 Author of the Month
  • Had an item that was trending
+10 more
wpbakery
says

Is there a way to check what shortcodes user used in the page/post? And based on that add a class to the body, or somewhere else in the templates file?

Thanks!

3535 posts
  • Power Elite Author: Sold more than $1M on Envato Market
  • Has sold $1M+ on Envato Market and is now a Power Elite Author
  • Had an item that was trending
  • Located in United States
+13 more
sevenspark
Moderator
says

Off the top of my head, you’ll probably want to look into using the body_class filter. You can read a good post on it here: http://www.nathanrice.net/blog/wordpress-2-8-and-the-body_class-function/

This is the basic idea:


add_filter('body_class', 'my_body_classes');

function my_body_classes($classes, $class) {
    // add 'my-class' to the $classes array
    $classes[] = 'my-class';
    // return the $classes array
    return $classes;
}

I’m not sure if you can call add_filter directly in your shortcode or if you’ll need to be more creative.

Hope that helps :)

838 posts
  • Power Elite Author: Sold more than $1M on Envato Market
  • Won a competition
  • Became a Top 20 Author of the Month
  • Had an item that was trending
+10 more
wpbakery
says
Off the top of my head, you’ll probably want to look into using the body_class filter. You can read a good post on it here: http://www.nathanrice.net/blog/wordpress-2-8-and-the-body_class-function/

This is the basic idea:


add_filter('body_class', 'my_body_classes');

function my_body_classes($classes, $class) {
    // add 'my-class' to the $classes array
    $classes[] = 'my-class';
    // return the $classes array
    return $classes;
}

I’m not sure if you can call add_filter directly in your shortcode or if you’ll need to be more creative.

Hope that helps :)

Thanks! This is actually a good idea! To go from the opposite direction. Thanks!

by
by
by
by
by
by