|  | 
| Condition check for plugin - is_plugin_active | 
Recently When I was creating a theme for wordpress using Bootstrap 3. I decided to add bootstrap CPT Carousel plugin.
When I added the shortcode in the homepage it worked properly but when plugin is not active it prints the short code [image-carousel"] on the homepage.
The solution I found was checking if the plugin is active or not.
It is a simple but very interesting check for the plugin to find if the plugin you are looking to work in your theme is active or not. use the following code for condition check for plugin active.
<?php
  // Include path to the Plugin directory.
  // This snippet only works for front end.
  include_once( ABSPATH . 'wp-admin/includes/plugin.php' );
  // check for plugin using plugin name
  if ( is_plugin_active( 'cpt-bootstrap-carousel/cpt-bootstrap-carousel.php' ) ) {
    echo do_shortcode('[image-carousel"]');
  }
?>
Codex Function reference for is_plugin_active
 
No comments :
Post a Comment