Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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

2 Answers 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!

share|improve this answer
1  
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

 
discard

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.