If I write a plugin and register a shortcode using this code:
add_shortcode('footag', 'footag_func');
and a user uses this in their post:
[FOOTAG]
Is it supposed to work?
If I write a plugin and register a shortcode using this code:
add_shortcode('footag', 'footag_func');
and a user uses this in their post:
[FOOTAG]
Is it supposed to work?
Comments are closed.
Short Answer
Yes, shortcodes are case sensitive
Longer Answer
It’s really easy to build a test case for this and see.
Longest Answer
Read the source.
The “magic” with shortcodes happens in
do_shortcode
, so let’s take a look at that.Hmmm,
$shortcode_tags
— probably get’s set up inadd_shortcode
:So that’s just a key value part of
$shortcode_name => $a_callablle
. Makes sense.Looks like most of the magic of
do_shortcode
takes place in building the regular expression to match shortcodes themselves. All that happens inget_shortcode_regex
, so let’s take a look there:Very well commented in the core, so not much to explain here. The key part is here:
Which essentially will get used later to explicitly match any of the registered shortcode names. Notice that no text processing is done other than
preg_quote
, so WP will only try to match the explicit values passed in toadd_shortcode
as the shortcode name. It’s looking like shortcodes are case sensitive so far.Next we need to take a look at the flags where the regular expression built in
get_shortcode_regex
is used. The relevant bit ofdo_shortcode
.The slashes delimit the regular expression, letters after the closing slash are PRCE flags or modifiers.
If we saw an
i
there it would be case insensitive. We only have ans
(meaning a.
matches all characters including the newline).So, yes, shortcodes are case sensitive.