if plugin is active? check if plugin is enabled or not?

I’m using the mingle plugin and the mingle-forum plugin.

I want to show a certain part on my site only if those two plugins are active. How can I solve this?

Read More
<?php if ( is_plugin_active('mingle-forum') ) { ?>
                    <div id="login"><?php include (TEMPLATEPATH . '/inc/userlogin.php' ); ?></div>
                <?php } ?>

This throws a php error. Call to undefined function is_plugin_active

Any idea what I’m doing wrong?

update:

<?php if ( plugin_active('plugin-directory/mingle-forum/wpf-main.php') ) { ?>
                    <div id="login"><?php include (TEMPLATEPATH . '/inc/userlogin.php' ); ?></div>
                <?php } ?>

Related posts

Leave a Reply

5 comments

  1. There are two way by which you can check plugin is active or not.

    1. You can use is_plugin_active function to check plugin active or
      not.
    2. If plugin have class then you can check like below-

      if (class_exists('YITH_Woocompare_Frontend')) 
      {
      echo 'your code';
      }
      

    The above class related to YITH WooCommerce Compare plugin . The above code check if class exist then only you code inside the bracket will execute.

  2. You can also try to check plugin is Active or Not

    $pluginList = get_option( 'active_plugins' );
    $plugin = 'PLUGIN_DIR/FILE_NAME.php'; 
    if ( in_array( $plugin , $pluginList ) ) {
        // Plugin 'mg-post-contributors' is Active
    }
    

    Also try below code for simplicity

    if ( is_plugin_active( 'PLUGIN_DIR/FILE_NAME.php' ) ) {
      //plugin is activated
    } 
    
  3. You can simply use the WordPress default function. This function exists in wp-admin/includes/plugin.php.

    Simply pass the Path to the plugin file relative to the plugins directory.

    $pluginPath = 'akismet/akismet.php';
    if ( is_plugin_active( $pluginPath ) ) {
        echo 'Plugin is activated';
    } else {
       echo 'Plugin is not activated';
    }
    

    For more details on is_plugin_active please see the below link:

    https://developer.wordpress.org/reference/functions/is_plugin_active/