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.

I am looking to embed several shortcodes into my post template, but I want the tags to be conditional to a specific category (and subcats).

I've looked through the codex, but I'm unsure where to start.

share|improve this question

1 Answer 1

up vote 1 down vote accepted

If you're embedding the code directly into the template file, why bother with shortcodes?

Simply extract the code from the add_shortcode() function call, and add it to your template, wrapped in an appropriate conditional tag, such as in_category(), e.g.:

if ( in_category( $cat ) ) {
     // put shortcode code here
}

Note: the $cat argument can be an ID, name, or slug.

share|improve this answer
    
I'll be using the template tag for the shortcode, I just put that in to explain. Thanks for the help! –  Jason May 2 '11 at 18:37
    
@Jason Instead of copy&past the shortcode code, you could use echo do_shortcode('[your_shortcode]'); to call the shortcode in your conditional statement. –  rofflox May 2 '11 at 19:50

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.