WordPress.org

Ready to get started?Download WordPress

Codex

Attention Interested in functions, hooks, classes, or methods? Check out the new WordPress Code Reference!

Difference between revisions of "Function Reference/has shortcode"

(Example)
m (Usage)
Line 10: Line 10:
   
 
== Usage ==
 
== Usage ==
%%% <?php if( has_shortcode( $content, 'gallery' ) ) { } ?> %%%
+
%%% <?php if ( has_shortcode( $content, 'gallery' ) ) { } ?> %%%
   
 
==Example==
 
==Example==

Revision as of 19:36, 17 May 2013

Description

Checks whether the content passed contains a specific short code.

Parameters

$content
(string) (required) The content to search.
Default: None
$tag
(string) (required) The short code to search for.
Default: None

Return

(Bool) 
True if the short code is found, false otherwise.

Usage

 <?php if ( has_shortcode$content'gallery' ) ) { } ?> 

Example

<?php

$content = 'This is some text, perhaps pulled via $post->post_content. It has a [gallery] short code.';

if( has_shortcode( $content, 'gallery' ) ) {
    // The content has a [gallery] short code, so this check returned true.
}

?>

Change Log

Source File

has_shortcode() is located in wp-includes/shortcodes.php.

Related

Shortcode API

See also index of Function Reference and index of Template Tags.