0

Is it possible to check what shortcodes are used on opened page using PHP/WP functions?

Why do I need it? I have special div ("#page-navi") on every page and when user uses [portfolio] shortcode I want it to display its navigation in this exact div.

Or when user uses [gallery] I want to display "this is a gallery" in this div.

Any ideas? :)

2 Answers 2

2

Yes it is. Check this function (has_shortcode):

Check for a shortcode in a page/post content

One of the mistakes that many developers make when creating shortcodes (in themes and plugins) is always loading all scripts and styles. For efficiency’s sake, and also to better prevent conflicts, scripts and styles should only be loaded when they are needed. This is a really handy function that will let you perform any action you want, such as loading scripts and styles, when, and only when, a post has a particular shortcode.

This [wp-hackers] thread also has a couple of methods listed. Hope it helps!

1
  • 1
    Yes, +1 for the wptuts+ has_shortcode stuff!
    – soulseekah
    Oct 19, 2011 at 3:39
0

Well there is no native "portfolio" shortcode, so your talking about a theme or plugin that is enabling that.

With that being said the logic is not that you search for a shortcode and alter the output but rather you enable the output in the actual shortcode itself.

As you can see in the example here you can add style tags (such as a div) as an Attribute of a shortcode, http://codex.wordpress.org/Shortcode_API

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.