How to check if a shortcode is registered in WordPress

Quick and easy function to check if a plugin/theme/whatever has add/registered a shortcode in WordPress:

function is_shortcode_defined($shortcode)
{
	global $shortcode_tags;
	if(isset($shortcode_tags[$shortcode]))
		return TRUE;
	else
		return FALSE;
}

Just add this into your plugin or theme’s functions.php and wherever you need to check if the shortcode exists, just call is_shortcode_defined(“button”);  or something similar from an if statement, as such:

if( ! is_shortcode_defined("button") )
{
	add_shortcode("button", "my_button_function");
}

Hope this helps.

You might be interested in …

WordPress loops, latests posts, sticky posts and problems

WordPress

I just figured out a problem (or just a nuisance?) of WordPress 3.0.1 that was driving me crazy, but finally got it working as expected. To all you WordPress theme developers out there, I hope the following explanation of the problem and the solution will save you a few minutes or hours of head-scratching.

Read More

Setting up a hostname and Avahi (mDNS)

Speaking terminal

We previously made sure our machine can access the internet. In this post, we’ll configure our machine so that we can access it from the local network, without ever knowing its IP address.

Read More

Setting up an environment

Speaking terminal

So, in order to have a vanilla environment where I’ll get to play around and have to configure most of the stuff myself (in order to force myself to learn), I decided to install CentOS 7 in a virtual machine. This will give the added benefit of keeping snapshots so that in case I get […]

Read More

Leave a Reply

Your email address will not be published. Required fields are marked *