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

Problems with Mobile Broadband On Demand on a Mac (Vodafone Greece)

English, Mac

If you bought a pay-as-you-go Mobile Broadband On Demand from Vodafone Greece, that came with a 3G USB modem, model K3565 -Rev 2 (sometimes named K3565-H), by Huawei Technologies, and you are on a Mac (I’m on 10.6.4), you may have troubles making it work.

Read More

mb_strtok() – A PHP implementation

PHP

While developing a web app, I needed to use the php’s multibyte family of functions. Having to deal with Greek characters specifically (although I always use utf-8) I needed the multibyte equivalent of strtok() to tokenize a stream of Greek characters. A quick look in the php documentation yielded almost every other function, but nothing […]

Read More

Leave a Reply

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