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 …

Free Open Source Exchange Rates for PHP

English, PHP

Inspired by the Open Source Exchange Rates and money.js, I’ve developed a PHP class that consumes the openexchangerates.org service. Since the service fetches the exchange rates from the (unofficial) Google Calculator API, I played around with it as well, and found some differences on the exchange rates provided by the two services. It is probably […]

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

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 *