Skip to main content
improved formatting
Source Link
Evan Mattson
  • 956
  • 1
  • 10
  • 20

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
            break;
            
            case 'cat':
                // some code
            break;

            case 'asparagus':
                // some code
            break;

            default:
                // some code
            break;
 
        } // switch
    }

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
            break;
            
            case 'cat':
                // some code
            break;

            case 'asparagus':
                // some code
            break;

            default:
                // some code
            break;
 
        } // switch
    }

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
            break;
        
        case 'cat':
            // some code
            break;

        case 'asparagus':
            // some code
            break;
    } // switch
}
Source Link
Evan Mattson
  • 956
  • 1
  • 10
  • 20

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
            break;
            
            case 'cat':
                // some code
            break;

            case 'asparagus':
                // some code
            break;

            default:
                // some code
            break;

        } // switch
    }