The is_plugin_active() WordPress PHP function determines whether a specific plugin is active.
Usage
To use is_plugin_active(), simply provide the plugin’s path relative to the plugins directory:
if (is_plugin_active('plugin-directory/plugin-file.php')) { // The plugin is active }
Parameters
- $plugin (string) – Required. Path to the plugin file relative to the plugins directory.
More information
See WordPress Developer Resources: is_plugin_active()
This function only works for plugins installed in the plugins/ folder. Plugins in the mu-plugins/ folder can’t be “activated,” so this function will return false for those plugins.
Examples
Check if a plugin is active
This example checks if the ‘my-plugin/my-plugin.php’ plugin is active:
if (is_plugin_active('my-plugin/my-plugin.php')) { // The 'my-plugin' is active }
Conditionally display content if a plugin is active
This example displays custom content only if the ‘cool-plugin/cool-plugin.php’ plugin is active:
if (is_plugin_active('cool-plugin/cool-plugin.php')) { // Display custom content for 'cool-plugin' echo '<div>Thank you for using Cool Plugin!</div>'; }
Perform a specific action if a plugin is not active
This example shows a notice if the ‘newsletter/newsletter.php’ plugin is not active:
if (!is_plugin_active('newsletter/newsletter.php')) { // Display a notice about the 'newsletter' plugin echo '<div>Please activate the Newsletter plugin to receive our updates.</div>'; }
Check if a plugin is active and use its functions
This example checks if the ‘gallery-plugin/gallery-plugin.php’ plugin is active, and if so, it uses the plugin’s function to display a gallery:
if (is_plugin_active('gallery-plugin/gallery-plugin.php')) { // Use the 'gallery_plugin_display' function from 'gallery-plugin' gallery_plugin_display(); }
Run a function only if multiple plugins are active
This example checks if both ‘plugin-a/plugin-a.php’ and ‘plugin-b/plugin-b.php’ are active, and if so, it runs a custom function:
if (is_plugin_active('plugin-a/plugin-a.php') && is_plugin_active('plugin-b/plugin-b.php')) { // Both 'plugin-a' and 'plugin-b' are active my_custom_function(); }