I was wondering if it is possible to make shortcode not case sensitive, should be pretty straight forward but I want:
[test=1]
to work while written as
[TeST=1], [TEST=1]
And if so, how do I do it?
I was wondering if it is possible to make shortcode not case sensitive, should be pretty straight forward but I want:
[test=1]
to work while written as
[TeST=1], [TEST=1]
And if so, how do I do it?
Here is another simple idea for a case-insensitive shortcode:
/**
* Make a shortcode case insensitive via the the_content filter
*
* @param string $content
* @return string $content
*/
function my_case_insensitive_shortcode( $content )
{
$sc="test"; // Edit this shortcode name to your needs
$from = '['. $sc ;
$to = $from;
if( stristr( $content, $from ) )
$content = str_ireplace( $from, $to, $content );
return $content;
}
add_filter( 'the_content', 'my_case_insensitive_shortcode', 10 );
You could also use preg_replace()
, if you need more accurate replacements.
Writing this in the post editor
[test id="1"]
[tEsT id="2"]
[TeSt id="3"]
gives the following output before the do_shortcode
filter is activated with priority 11
:
[test id="1"]
[test id="2"]
[test id="3"]