834 posts
  • Power Elite Author: Sold more than $1M on Envato Market
  • Won a competition
  • Made it to the Authors' Hall of Fame
  • Has sold $1M+ on Envato Market and is now a Power Elite Author
+7 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!

3503 posts
  • Elite Author: Sold more than $75,000 on Envato Market
  • Has sold $750,000+ on Envato Market
  • Located in United States
  • Helps us moderate the forums
+10 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 :)

834 posts
  • Power Elite Author: Sold more than $1M on Envato Market
  • Won a competition
  • Made it to the Authors' Hall of Fame
  • Has sold $1M+ on Envato Market and is now a Power Elite Author
+7 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!

Helpful Information

  • Please read our community guidelines. Self promotion and discussion of piracy is not allowed.
  • Open a support ticket if you would like specific help with your account, deposits or purchases.
  • Item Support by authors is optional and may vary. Please see the Support tab on each item page.

Most of all, enjoy your time here. Thank you for being a valued Envato community member.

Post Reply

Format your entry with some basic HTML. Read the Full Details, or here is a refresher:

<strong></strong> to make things bold
<em></em> to emphasize
<ul><li> or <ol><li> to make lists
<h3> or <h4> to make headings
<pre></pre> for code blocks
<code></code> for a few words of code
<a></a> for links
<img> to paste in an image (it'll need to be hosted somewhere else though)
<blockquote></blockquote> to quote somebody

:grin: :shocked: :cry: Complete List of Smiley Codes

by
by
by
by
by
by