In WordPress, is_plugin_active() returns true when a given plugin is active on the current site. Otherwise it returns false.
The plugin is named by its path inside the plugins folder, such as akismet/akismet.php. Themes and plugins use this check to turn on extra features only when another plugin is ready.
Syntax
Use it as the test of an if statement.
WordPress
if ( is_plugin_active( 'akismet/akismet.php' ) ) {
// code for the true path
} else {
// code for the false path
}
Call
What it does
is_plugin_active( 'akismet/akismet.php' )
True if Akismet is active.
is_plugin_active( 'woocommerce/woocommerce.php' )
True if WooCommerce is active.
! is_plugin_active( $plugin )
True if the plugin is not active.
On the front end, load the function first with require_once ABSPATH . 'wp-admin/includes/plugin.php';.
Full declaration
WordPress
is_plugin_active( string $plugin ): bool
Parameters
Parameter
Description
$plugin
Required. The path of the main plugin file, relative to the plugins folder, for example akismet/akismet.php.
Return Value
Return Value
Description
bool
true if the plugin is active, otherwise false.
WordPress Examples
Three short theme examples. Each one shows what prints on the true path and the false path.
Example 1 — Include plugin.php first
Make the function available in a theme file.
WordPress
<?php
if ( ! function_exists( 'is_plugin_active' ) ) {
require_once ABSPATH . 'wp-admin/includes/plugin.php';
}
if ( is_plugin_active( 'akismet/akismet.php' ) ) {
echo 'Akismet is active.';
} else {
echo 'Akismet is not active.';
}
Output
Akismet is active (true):
Akismet is active.
Akismet is not active (false):
Akismet is not active.
How It Works
function_exists() checks if the function is already loaded.