Is it possible to make shortcodes NOT case sensitive?

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

Read More
[TeST=1], [TEST=1] 

And if so, how do I do it?

Related posts

2 comments

  1. 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.

    Example:

    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"]
    
  2. If you’re talking about a shortcode you’ve created yourself, you’d have to register all possibilities of case.

    If you want all shortcodes to be case-insensitive, you’d have to modify the shortcode handling code in the WordPress core includes (or override it I guess…)

    This question Are shortcodes case-sensitive? has some info on the necessary functions you’d have to modify.

Comments are closed.