[shortcode] Tell callback the shortcode name that matched the regex
-
I don’t see any way for a shortcode handler to determine which shortcode matched the regex that caused the callback. I use an overloaded handler to process a (large) number of different related cases, which I currently distinguish via their content or attributes. Using the shortcode name itself would be a much cleaner user interface. Example:
Preferred:
[Foo1 /] [Foo2 /]
[Foo1]case1[/Foo1] [Foo2]case2[/Foo2]
Today:
[Foo]case1|args[/Foo] [Foo]case2|args[/Foo]
[Foo arg='1']case1|args[/Foo] [Foo arg='2']case2|args[/Foo]
If this were the first release of the API we could just automatically add the shortcode name to the attribute list; but today that would break any existing plugins that are sensitive to the count of
shortcode_atts()[]
versus$atts[]
.But we could allow a magic default value in the call to
shortcode_atts()
:shortcode_atts(array('myname' <= '_shortcode_name'))
Or we could use a global variable (ugh) e.g.
$gShortcodeName
.(Sorry if I have overlooked any existing way to determine this; I couldn’t see one.)
- The topic ‘[shortcode] Tell callback the shortcode name that matched the regex’ is closed to new replies.