wpseek.com
Outil de recherche WordPress pour les développeurs et auteurs de thèmes



has_shortcode › WordPress Function

Depuis3.6.0
Dépréciéen/a
has_shortcode ( $content, $tag )
Paramètres: (2)
  • (string) $content Content to search for shortcodes.
    Requis: Oui
  • (string) $tag Shortcode tag to check.
    Requis: Oui
Retourne:
  • (bool) Whether the passed content contains the given shortcode.
Défini(e) dans:
Codex:

Determines whether the passed content contains the specified shortcode.



Source

function has_shortcode( $content, $tag ) {
	if ( ! str_contains( $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;
}