WordPress: Parameter for Shortcode function

I am trying to create a shortcode in WordPress, in which the function that is called with the shortcode tag gets the shortcode tag as parameter.

So say I have

Read More
<?php
var $shortcode = 'my_shortcode_tag';
add_shortcode( $shortcode, 'my_shortcode_function');
?>

then I want 'my_shortcode_function' to know the shortcode tag by it was called. I know that I could use attributes as in [my_shortcode_tag tag='my_shortcode_tag'] when I call the shortcode in my actual post, but I want to be able to just write [my_shortcode_tag] and my function to know that it was called by that tag. Is there a way to do this?

Related posts

Leave a Reply

1 comment

  1. This is sent in as the third argument to a shortcode function (as mentioned in the Shortcodes API).

    for example:

    add_shortcode( 'shortcode1', 'my_shortcode_function');
    add_shortcode( 'shortcode2', 'my_shortcode_function');
    
    function my_shortcode_function($atts, $content, $sc) {
        return $sc;
    }
    

    this will output the name of the shortcode called for that function.