has_shortcode
function syntax
The has_shortcode
function gets two parameters, a content and a tag.
Developers use this function to check if a shortcode is available in the content or not.
has_shortcode($content, $tag)
Behind the scenes, WordPress uses regex to find shortcodes in content and checks if a specific shortcode is available between them or not.
But this function does more than just a regex checking.
has_shortcode
also checks if the shortcode is a real shortcode in WordPress or Not.
has_shortcode
function usage example
this function has a simple syntax to use. We’re going to try it in a working example:
if(has_shortcode('[test]', 'test')){
// test is not a default WP shortcode
// if you or a plugin did not defined it, will return false
}
if(has_shortcode('[video]', 'video')){
// test is a default WP shortcode
// if you did not removed it, this condition is true
}
If you are interested in shortcodes in WordPress, you can read my tutorials:
written by Mehdi Nazari about in WordPress WordPress Plugins WordPress Themes