WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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

Possible Duplicate:
current_shortcode() - detect currently used shortcode

I'm dynamically generating shortcodes with my plugin like this:

foreach ($options['grids'] as $grid) {
    add_shortcode($grid['shortcode'], array($this, 'print_shortcode'));

But the problem is, in the callback function I need to print different content, based on the shortcode's name.

My question is - how would I get the shortcode's name from within print_shortcode() ?

Thank you!

share|improve this question

marked as duplicate by toscho Jul 11 '12 at 5:17

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

What does the $options['grids'] contains? – brasofilo Jul 11 '12 at 0:25

The shortcode's name is referred to as the tag. The tag is actually the 3rd (and last) parameter passed to the shortcode's callback function.

So your callback should look something like this:

function print_shortcode($atts, $content, $tag) {
    // $atts - array of attributes passed from shortcode
    // $content - content between shortcodes that have enclosing tags eg: [tag]content[/tag]
    // $tag - shortcode name

    // do something... perhaps:

    switch($tag) {
        case 'dog':
            // some code

        case 'cat':
            // some code

        case 'asparagus':
            // some code
    } // switch
share|improve this answer

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