开发者

Filter only shortcode from a post

开发者 https://www.devze.com 2023-01-16 19:00 出处:网络
I am using a contact page plugin for my blog.The shortcode using for this is [my-shortcode]. Is ther开发者_JS百科e anyways to filter only the shortcode from the content.

I am using a contact page plugin for my blog.The shortcode using for this is [my-shortcode]. Is ther开发者_JS百科e anyways to filter only the shortcode from the content. Eg: Test post [my-shortcode] Demo widget.here i need to filter only the shortcode.Thank you


You can use regex to get the value of brackets within a string like so.

if(preg_match_all('/\[(.*?)\]/',$_POST['my_key'],$matches))
{
    foreach($matches as $match)
    {
        if($match[1] == 'my-short-code')
        {
            //Do whetever
            break 2;
        }
    }
}

Note: match[1] may be match[0]

0

精彩评论

暂无评论...
验证码 换一张
取 消