Checking if a Widget has Been Activated in WordPress

Sometimes, it is extremely difficult to find out if a function already exists in WordPress or if you need to create one yourself to get it to function how you need it to. I had created a widget for my Magazine Basic 2.0 free premium theme and I needed to make sure that if it was added to a user’s sidebar, then certain functionality would occur.

I couldn’t find out how to do it so I decided to use PHP Sessions. The only problem with this is that WordPress doesn’t allow you to upload a theme to WordPress.org that uses Sessions. So I searched and searched and finally found what I need buried deep in the WordPress code. To check if a widget has been activated you need to use the following code.
is_active_widget('name_of_widget')
Replace name_of_widget with the original function name of your widget. If you were using my Features Post widget then the code to check if it is activated would be:
is_active_widget('widget_myFeature')

Share this:

Email
Facebook
Twitter
Pinterest
Pocket

Premium Themes for WordPress

Looking for an easy-to-use Premium Theme for WordPress? Check out Themes by bavotasan.com and have your site up and running in no time.

Use this WordPress website builder to build powerful websites in no time for your or your clients.

WordPress Hosting

WP Engine – designed from the ground-up to support and enhance the workflow of web designers.

Bluehost – providing quality web hosting solutions since 1996.

About the author

Picture of Luke Perrie

Luke Perrie