Check if Certain Plugin is Active in WordPress

[ad_1]

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
}
[ad_2]

Leave a Reply

Random Post Selection ::

Recent Posts

Unlock Unlimited Downloads