Advertisement
firoze

Conditional enqueue in wordpress

Aug 23rd, 2018
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.66 KB | None | 0 0
  1. /*-------------------------------------------------------------------------
  2. # if custom post type publish post 0 then scripe will not load
  3. # when will get at least 1 post publish then script will load
  4. ---------------------------------------------------------------------------*/
  5.  
  6. $count_posts = wp_count_posts('slide'); // here "slide" is the name of post_type
  7. $count = $count_posts->publish;
  8.  
  9. if($count > 0){
  10.     wp_enqueue_style('owl-carousel',plugin_dir_url(__FILE__).'assets/css/owl.carousel.css',array(),PLUGIN_VERSION);
  11.     wp_enqueue_script('owl-carousel',plugin_dir_url(__FILE__).'assets/js/owl.carousel.min.js',array('jquery'),PLUGIN_VERSION,true);
  12. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement