Checking if a Widget has Been Activated in WordPress
by Bandicoot Marketing on | Posted in Tutorials | 6 comments
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')
6 comments for “Checking if a Widget has Been Activated in WordPress”