Check if Certain Plugin is Active in WordPress

How to Check if Certain Plugin is Active in WordPress

in Functions
Google+ LinkedIn

While developing a theme or a plugin, we sometimes need to check if a particular third-party plugin is active and only perform certain actions if it is. This might be due to my customization adding some extra functionality on top of the other plugin. Therefore it doesn’t make sense to have my customization active while the dependent plugin is not active. The situation is the same when creating add-ons for an existing plugin.

For example, the Genesis theme by StudioPress, checks whether an SEO plugin is installed and activated, and if not, it will load its own SEO functionality. In that case, it doesn’t make sense to duplicate SEO options, so its either the plugin that is used, or the theme’s SEO features.

Use this code snippet below to check if a plugin is active or not. Usually you will add this code in your functions.php for adding further functionality. With this simple method you’ll be safe when adding functionality that is meant to work with a particular plugin since you’ll always be able to check if the plugin is enabled.

// check if certain plugin is active
if ( is_plugin_active( 'plugin-directory/plugin-file.php' ) ) {
    // do something if plugin is active
}

For example we will see how to perform this check with Jetpack plugin.

// check if jetpack plugin is active
if ( is_plugin_active( 'jetpack/jetpack.php' ) ) {
    // do something if Jetpack is active
}

Share the love

If you like this snippet, share it with others!

Leave a Reply

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