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

| WordPress
Check If a WordPress Plugin is Activated with PHP

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:

if ( is_plugin_active( 'plugin-folder/plugin-file.php' ) ):

    echo 'The plugin IS activated';

else:

    echo 'The plugin is NOT activated';

endif;

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:

include_once( ABSPATH . 'wp-admin/includes/plugin.php' );


About the author

Valentín creates beautiful designs from amongst the tequila plants of Jalisco, Mexico. You can see Valentín's design work all over this site and you can often find him helping members in support.