Check If A WordPress Plugin Is Active

If you ever have to write code that is dependent on a specific plugin being active, WordPress has you covered with the is_plugin_active() function.

All you need to do is pass in the plugin basename and WordPress will do the checking to see if the plugin is active.

How do you get the plugin basename you ask?  The plugin basename is the file name for a single file plugin or the directory and file name for multi-file plugins. In other words, the plugin basename is the base plugin path from plugins directory.

If you are going to check if a WordPress plugin is active, you probably already know what the plugin base name is, but you can also use the plugin_basename() function, which requires you to pass in the file path of the plugin.

Did you want to check if a plugin is inactive? As of version 3.1 you can just use the is_plugin_inactive() function. However, it is more backward compatible at this point just to use !is_plugin_active( $basename ).

Finally, if you happen to be using WordPress Multisite, you may also want to check if a plugin has been network activated. This can be done using the is_plugin_active_for_network() function.

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.