1

Assuming there is some function or variable that allows the shortcode access to its name, and for sake here I will term that $scName, is something like this possible:

function test_return_shortcode_name( $atts ) {
    return $scName;
}
add_shortcode( 'myName', 'test_return_shortcode_name' );

And so for this basic example, this shortcode:

[myName]

Which would return the actual name as text

myName

Does such functionality exist to access the designated name from within the function associated to it?

2

1 Answer 1

2

A shortcode can access its own name - it is supplied as third parameter to the shortcode's callback function, just like that:

function test_shortcode_callback( $atts = array(), $content = null, $tag ) {
    return $tag;
}
add_shortcode( 'test_shortcode', 'test_shortcode_callback' );

// So running this shortcode
[test_shortcode]
// Will return this
test_shortcode

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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