Skip to content

Instantly share code, notes, and snippets.

@sheabunge
Forked from r-a-y/shortcode.php
Last active June 28, 2017 04:29
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sheabunge/2916977 to your computer and use it in GitHub Desktop.
Save sheabunge/2916977 to your computer and use it in GitHub Desktop.
Check if a shortcode exists in WordPress
<?php
if ( ! function_exists( 'shortcode_exists' ) ) :
/**
* Check if a shortcode is registered in WordPress.
*
* Examples: shortcode_exists( 'caption' ) - will return true.
* shortcode_exists( 'blah' ) - will return false.
*
* @param string $shortcode The name of the shortcode to check
* @return bool Whether the shortcode exists or not
*/
function shortcode_exists( $shortcode ) {
global $shortcode_tags;
return array_key_exists( $shortcode, $shortcode_tags ) );
}
endif;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment