67 posts
  • Has been part of the Envato Community for over 1 year
  • 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 6 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
  • Has been part of the Envato Community for over 1 year
  • 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.

Helpful Information

  • Please read our community guidelines. Self promotion and discussion of piracy is not allowed.
  • Open a support ticket if you would like specific help with your account, deposits or purchases.
  • Item Support by authors is optional and may vary. Please see the Support tab on each item page.

Most of all, enjoy your time here. Thank you for being a valued Envato community member.

Post Reply

Format your entry with some basic HTML. Read the Full Details, or here is a refresher:

<strong></strong> to make things bold
<em></em> to emphasize
<ul><li> or <ol><li> to make lists
<h3> or <h4> to make headings
<pre></pre> for code blocks
<code></code> for a few words of code
<a></a> for links
<img> to paste in an image (it'll need to be hosted somewhere else though)
<blockquote></blockquote> to quote somebody

:grin: :shocked: :cry: Complete List of Smiley Codes

by
by
by
by
by
by