Use is_plugin_active() to check If a WordPress Plugin is Activate

WordPress has a ton of hooks and methods to check specific tasks. These are very useful when developing plugins and themes.
In this post I’ll show you how to use the is_plugin_active() method to check if another plugin is installed and activated.
Why would you use is_plugin_active()? Let’s say you’re creating a custom plugin that depends on another plugin being installed and activated. For example: your new plugin will add new features to WooCommerce.
The code
If your code is executed on the admin area, use this sample code:
{codecitation php}if ( is_plugin_active( ‘plugin-folder/plugin-file.php’ ) ):
echo ‘The plugin IS activated’;
else:
echo ‘The plugin is NOT activated’;
endif;{/codecitation}
Replace ‘plugin-folder/plugin-file.php’ with the folder and main file name of the plugin you want to target. For example: ‘woocommerce/woocommerce.php’ to check if WooCommerce is installed and activated.
If the code will execute in the public area of the site, add this line of PHP code above the previous one:
{codecitation php}include_once( ABSPATH . ‘wp-admin/includes/plugin.php’ );{/codecitation}
Thank you so much, i was looking for a quick example and this post is probably the best i could i have found
¡Muchas gracias Valentín! I believe you’re the only one with a clear example on this function in the whole Internet. The ‘plugin-folder/plugin-file.php’ path wasn’t totally clear to me until I read your example! Wohoo!
I think that to make this compatible with WordPress coding best practices, you need to use WP_PLUGIN_DIR (if defined) instead of a hard-coded path.
Also see:
https://wordpress.stackexchange.com/questions/99444/is-plugin-active-returning-false-on-active-plugin
WordPress.org:@brianbrown
“ActivatED”!
ACTIVATED!!!!!!