Skip to content

Instantly share code, notes, and snippets.

@bueltge
Created August 18, 2011 22:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bueltge/1155369 to your computer and use it in GitHub Desktop.
Save bueltge/1155369 to your computer and use it in GitHub Desktop.
has_shortcode()
// check the current post for the existence of a short code
function has_shortcode( $shortcode = NULL ) {
$post_to_check = get_post( get_the_ID() );
// false because we have to search through the post content first
$found = false;
// if no short code was provided, return false
if ( ! $shortcode ) {
return $found;
}
// check the post content for the short code
if ( stripos( $post_to_check->post_content, '[' . $shortcode) !== FALSE ) {
// we have found the short code
$found = TRUE;
}
// return our final results
return $found;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment