WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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? :)

share|improve this question

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!

share|improve this answer
Yes, +1 for the wptuts+ has_shortcode stuff! – soulseekah Oct 19 '11 at 3:39
Thanks a lot! :) – Rutwick Gangurde Oct 19 '11 at 3:49

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

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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