has_shortcode() – Whether the passed content contains the specified shortcode

You appear to be a bot. Output may be restricted

Description

Whether the passed content contains the specified shortcode

Usage

$bool = has_shortcode( $content, $tag );

Parameters

$content
( string ) required – Content to search for shortcodes.
$tag
( string ) required – Shortcode tag to check.

Returns

bool Whether the passed content contains the given shortcode.

Source

File name: wordpress/wp-includes/shortcodes.php
Lines:

1 to 21 of 21
function has_shortcode( $content, $tag ) {
  if ( false === strpos( $content, '[' ) ) {
    return false;
  }

  if ( shortcode_exists( $tag ) ) {
    preg_match_all( '/' . get_shortcode_regex() . '/', $content, $matches, PREG_SET_ORDER );
    if ( empty( $matches ) ) {
      return false;
    }

    foreach ( $matches as $shortcode ) {
      if ( $tag === $shortcode[2] ) {
        return true;
      } elseif ( ! empty( $shortcode[5] ) && has_shortcode( $shortcode[5], $tag ) ) {
        return true;
      }
    }
  }
  return false;
}
 

 View on GitHub View on Trac