WordPress at a glance

is_plugin_active() WP 2.5.0

Determines whether a plugin is active. Works in the dashboard only. Conditional tag.

The function is located in wp-admin/includes/plugin.php, so it only works in the dashboard. Use it on admin_init action or later.

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.000043s = very fast | 50000 times = 0.63s = 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.
 */
include_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.

Code of is plugin active: wp-admin/includes/plugin.php WP 5.2.3

<?php
function is_plugin_active( $plugin ) {
	return in_array( $plugin, (array) get_option( 'active_plugins', array() ) ) || is_plugin_active_for_network( $plugin );
}

Related Functions

From tag: plugin

More from tag: Conditional tags (all)

More from category: Plugins, Hooks

No comments
    Hello, !     Log In . Register