67 posts
  • Sells items exclusively on Envato Market
DesignLinks says

has_shortcode() return true if content passed through the function contains a specific shortcode. Detail here: https://codex.wordpress.org/Function_Reference/has_shortcode

I’ve two questions here …

1: Is there any disadvantage of using it?

2: Is it allowed to be used in any theme or plugin here. Because i’ve read somewhere that it might not be allowed to use because it can interfere with other shortcodes.

214 posts
  • Has referred 1+ members
  • Has collected 50+ items on Envato Market
  • Has been part of the Envato Community for over 5 years
  • Sells items exclusively on Envato Market
agusmu says

Basically, this will limit you to run this function on specific content then run something else when it returns true.

I can say, it is allowed, it doesn’t change your content, but it really depends on what is the purpose of using this function on your theme…

if you want to use it to include custom script conditionally when a shortcode is called, then I will not recommend this, because it only limits your shortcode to be used on specific content. for conditional script loading on shortcode, you can directly use wp_enqueue_script inside your shortcode handler. source: http://scribu.net/wordpress/conditional-script-loading-revisited.html

67 posts
  • Sells items exclusively on Envato Market
DesignLinks says

Basically, this will limit you to run this function on specific content then run something else when it returns true.

I can say, it is allowed, it doesn’t change your content, but it really depends on what is the purpose of using this function on your theme…

if you want to use it to include custom script conditionally when a shortcode is called, then I will not recommend this, because it only limits your shortcode to be used on specific content. for conditional script loading on shortcode, you can directly use wp_enqueue_script inside your shortcode handler. source: http://scribu.net/wordpress/conditional-script-loading-revisited.html

Thnx buddy for giving time for reply.

But i really dont undertand this statment …

Basically, this will limit you to run this function on specific content then run something else when it returns true.

i just want to use this function in conditional statment just like this to check if content has any video shortcode.

has_shortcode(get_the_content(), 'video')

if it returns true i will use some customized get_the_content() function to display the post content.

by
by
by
by
by
by