is_plugin_active()
Determines whether a plugin is active. Works in the dashboard only. Conditional tag.
The function is in the file wp-admin/includes/plugin.php, which means it works in the admin panel.
You can use the function very early, but it is recommended to use it on admin_init hook or later, because other code can activate or deactivate plugins before those hook.
For the function to work on the front you need to connect the file:
require_once ABSPATH . 'wp-admin/includes/plugin.php';
1 time — 0.000043 sec (very fast) | 50000 times — 0.63 sec (very fast) | PHP 7.0.14, WP 4.7
No Hooks.
Return
true|false
. True, if in the active plugins list. False, not in the list.
Usage
is_plugin_active( $plugin );
- $plugin(string) (required)
- Path to the plugin file relative to the plugins directory.
Examples
#1 In the dashboard, check if the plugin is activated
/** * Check if the plugin is in the active plugins list. */ if ( is_plugin_active( 'plugin-directory/plugin-file.php' ) ) { echo 'Plugin is active'; } else { echo 'Plugin is not active'; }
#2 Check if the plugin is active not in the dashboard (on front-end).
/** * Check if the plugin is in the active plugins list from front-page. */ require_once ABSPATH . 'wp-admin/includes/plugin.php'; if ( is_plugin_active( 'plugin-directory/plugin-file.php' ) ) { echo 'Plugin is active' }
Changelog
Since 2.5.0 | Introduced. |
is_plugin_active() is plugin active code WP 6.7.1
function is_plugin_active( $plugin ) { return in_array( $plugin, (array) get_option( 'active_plugins', array() ), true ) || is_plugin_active_for_network( $plugin ); }