title: How to add owl carousel to front page
body: <p>I'm using a pre made theme for my site.  I would like to add an owl carousel to the top of my front page that displays the most popular posts from the last month on my site.  The pre made theme already comes with owl carousel.  So my question is how can I add the carousel to my front page now?  I found the owl carousel widget in the plugins file so I tried adding the widget to my front page but I don't think I added it right because nothing changed.  Does anyone have any suggestions for how I could achieve this?</p>
  
  <p>here are my full theme files if needed - <a href="https://www.dropbox.com/s/624p2sdn2i0jsqf/novablogshare.zip?dl=0" rel="noreferrer">https://www.dropbox.com/s/624p2sdn2i0jsqf/novablogshare.zip?dl=0</a></p>
  
  <p>my custom front-page.php</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;?php
  
  get_header(); 
  the_widget("owl_Widget"); //trying to call the owl carousel widget but it is not working
  
  ?&gt;
  
  
  &lt;script&gt;
      var now=2; // when click start in page 2
  
      jQuery(document).on('click', '#load_more_btn', function () {
  
          jQuery.ajax({
              type: "POST",
              url: "&lt;?php echo get_site_url(); ?&gt;/wp-admin/admin-ajax.php",
              data: {
                  action: 'my_load_more_function', // the name of the function in functions.php
                  paged: now, // set the page to get the ajax request
                  posts_per_page: 15  //number of post to get (use 1 for testing)
              },
              success: function (data) {
  
              if(data!=0){
                  jQuery("#ajax").append(data);  // put the content into ajax container
                  now=now+1; // add 1 to next page
              }else{
                  jQuery("#load_more_btn").hide();
              }
              },
              error: function (errorThrown) {
                  alert(errorThrown); // only for debuggin
              }
          });
      });
  &lt;/script&gt;
  
  &lt;section id="ajax"&gt;&lt;!-- i have to change div to section, maybe a extra div declare --&gt;
  &lt;?php
  
  $the_query = new WP_Query( [
      'posts_per_page' =&gt; 15, // i use 1 for testing
          'orderby' =&gt; 'post_date',
  'order' =&gt; 'DESC',
      'paged' =&gt; get_query_var('paged', 1) //page number 1 on load
  ] );
  
  if ($the_query-&gt;have_posts()) {
  
          $i = 0;
          $j = 0;
          while ($the_query-&gt;have_posts()) {
              $the_query-&gt;the_post();
  
              if ( $i % 5 === 0 ) { // Large post: on the first iteration and every 7th post after... ?&gt;
                  &lt;div class="row"&gt;
                      &lt;article &lt;?php post_class( 'col-sm-12 col-md-12' ); ?&gt;&gt;
                          &lt;div class="large-front-container"&gt;
                              &lt;?php the_post_thumbnail('full', array('class' =&gt; 'large-front-thumbnail')); ?&gt;
                          &lt;/div&gt;
                          &lt;div class="front-page-date"&gt;&lt;?php echo str_replace('mins', 'minutes', human_time_diff( get_the_time('U'), current_time('timestamp') ) . ' ago'); ?&gt;&lt;/div&gt;
                          &lt;div class="front-page-post-title"&gt;&lt;a href="&lt;?php the_permalink(); ?&gt;"&gt;&lt;?php the_title(); ?&gt;&lt;/a&gt;&lt;/div&gt;
                          &lt;p class="front-page-post-excerpt"&gt;&lt;?php echo get_the_excerpt(); ?&gt;&lt;/p&gt;
                          &lt;div class="front-page-post-info"&gt;
                              &lt;a class="moretext" href="&lt;?php the_permalink(); ?&gt;"&gt;Read more&lt;/a&gt;
                              &lt;?php get_template_part( 'includes/front-shop-the-post' ); ?&gt;
                              &lt;?php get_template_part( 'includes/share-buttons' ); ?&gt;
                              &lt;div class="front-comments"&gt;&lt;?php comments_popup_link ('0', '1', '%', 'comment-count', 'none'); ?&gt;&lt;/div&gt;
                          &lt;/div&gt;
                      &lt;/article&gt;
                  &lt;/div&gt;
              &lt;?php } else { // Small posts ?&gt;
                  &lt;?php if($j % 2 === 0){ echo '&lt;div class="row"&gt;';} ?&gt;
                  &lt;article &lt;?php post_class( 'col-sm-6 col-md-6' ); ?&gt;&gt;
                      &lt;div class="two-front-container"&gt;
                      &lt;?php the_post_thumbnail('full', array('class' =&gt; 'medium-front-thumbnail')); ?&gt;
                          &lt;div&gt;
                      &lt;div class="front-page-date"&gt;&lt;?php echo human_time_diff( get_the_time('U'), current_time('timestamp') ) . ' ago'; ?&gt;&lt;/div&gt;
                      &lt;div class="front-page-post-title"&gt;&lt;a href="&lt;?php the_permalink(); ?&gt;"&gt;&lt;?php the_title(); ?&gt;&lt;/a&gt;&lt;/div&gt;
                      &lt;p class="front-page-post-excerpt"&gt;&lt;?php echo get_the_excerpt(); ?&gt;&lt;/p&gt;
                      &lt;div class="front-page-post-info"&gt;
                          &lt;a class="moretext" href="&lt;?php the_permalink(); ?&gt;"&gt;Read more&lt;/a&gt;
                          &lt;?php get_template_part( 'includes/front-shop-the-post' ); ?&gt;
                          &lt;?php get_template_part( 'includes/share-buttons' ); ?&gt;
                          &lt;div class="front-comments"&gt;&lt;?php comments_popup_link ('0', '1', '%', 'comment-count', 'none'); ?&gt;&lt;/div&gt;
                      &lt;/div&gt;
                  &lt;/article&gt;
                  &lt;?php $j++; if($j % 2 === 0){ echo '&lt;/div&gt;';}?&gt;
                  &lt;?php
              }
              $i++;
          }?&gt;
      &lt;?php
  }?&gt;
  &lt;/section&gt;
  
  &lt;button id="load_more_btn"&gt;Load More Posts&lt;/button&gt; &lt;!-- button out of ajax container for load content and button displayed at the bottom --&gt;
  &lt;?php
  get_footer();</code></pre>
  </div>
  </div>
  </p>
  
  <p>functions for my front-page </p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>add_action('wp_ajax_my_load_more_function', 'my_load_more_function');
  add_action('wp_ajax_nopriv_my_load_more_function', 'my_load_more_function');
  
  function my_load_more_function() {
  
      $query = new WP_Query( [
          'posts_per_page' =&gt; $_POST["posts_per_page"],
          'orderby' =&gt; 'post_date',
  'order' =&gt; 'DESC',
          'paged' =&gt; get_query_var('paged', $_POST["paged"])
      ] );
  
  
      if ($query-&gt;have_posts()) {
  
          $i = 0;
          $j = 0;
  
          while ($query-&gt;have_posts()) {
                  $query-&gt;the_post();
  
              if ( $i % 5 === 0 ) { // Large post: on the first iteration and every 7th post after... ?&gt;
   &lt;div class="row"&gt;
                      &lt;article &lt;?php post_class( 'col-sm-12 col-md-12' ); ?&gt;&gt;
                          &lt;div class="large-front-container"&gt;
                              &lt;?php the_post_thumbnail('full', array('class' =&gt; 'large-front-thumbnail')); ?&gt;
                          &lt;/div&gt;
                          &lt;div class="front-page-date"&gt;&lt;?php echo str_replace('mins', 'minutes', human_time_diff( get_the_time('U'), current_time('timestamp') ) . ' ago'); ?&gt;&lt;/div&gt;
                          &lt;div class="front-page-post-title"&gt;&lt;a href="&lt;?php the_permalink(); ?&gt;"&gt;&lt;?php the_title(); ?&gt;&lt;/a&gt;&lt;/div&gt;
                          &lt;p class="front-page-post-excerpt"&gt;&lt;?php echo get_the_excerpt(); ?&gt;&lt;/p&gt;
                          &lt;div class="front-page-post-info"&gt;
                              &lt;a class="moretext" href="&lt;?php the_permalink(); ?&gt;"&gt;Read more&lt;/a&gt;
                              &lt;?php get_template_part( 'includes/front-shop-the-post' ); ?&gt;
                              &lt;?php get_template_part( 'includes/share-buttons' ); ?&gt;
                              &lt;div class="front-comments"&gt;&lt;?php comments_popup_link ('0', '1', '%', 'comment-count', 'none'); ?&gt;&lt;/div&gt;
                          &lt;/div&gt;
                      &lt;/article&gt;
                  &lt;/div&gt;
              &lt;?php } else { // Small posts ?&gt;
                  &lt;?php if($j % 2 === 0) echo '&lt;div class="row"&gt;'; ?&gt;
                                  &lt;article &lt;?php post_class( 'col-sm-6 col-md-6' ); ?&gt;&gt;
                      &lt;div class="two-front-container"&gt;
                      &lt;?php the_post_thumbnail('full', array('class' =&gt; 'medium-front-thumbnail')); ?&gt;
                          &lt;div&gt;
                      &lt;div class="front-page-date"&gt;&lt;?php echo human_time_diff( get_the_time('U'), current_time('timestamp') ) . ' ago'; ?&gt;&lt;/div&gt;
                      &lt;div class="front-page-post-title"&gt;&lt;a href="&lt;?php the_permalink(); ?&gt;"&gt;&lt;?php the_title(); ?&gt;&lt;/a&gt;&lt;/div&gt;
                      &lt;p class="front-page-post-excerpt"&gt;&lt;?php echo get_the_excerpt(); ?&gt;&lt;/p&gt;
                      &lt;div class="front-page-post-info"&gt;
                          &lt;a class="moretext" href="&lt;?php the_permalink(); ?&gt;"&gt;Read more&lt;/a&gt;
                          &lt;?php get_template_part( 'includes/front-shop-the-post' ); ?&gt;
                          &lt;?php get_template_part( 'includes/share-buttons' ); ?&gt;
                          &lt;div class="front-comments"&gt;&lt;?php comments_popup_link ('0', '1', '%', 'comment-count', 'none'); ?&gt;&lt;/div&gt;
                      &lt;/div&gt;
                  &lt;/article&gt;
                  &lt;?php $j++; if($j % 2 === 0) echo '&lt;/div&gt;'; ?&gt;
                  &lt;?php
              }
              $i++;
  
          }
          wp_reset_query();
      }else{
          return 0;
      }
  
      exit;
  }</code></pre>
  </div>
  </div>
  </p>
  
  <p>owl-carousel.php (located in plugins folder)</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;?php
  /*
    Plugin Name: Owl Carousel
    Description: A simple plugin to include an Owl Carousel in any post
    Author: Pierre JEHAN
    Version: 0.5.3
    Author URI: http://www.pierre-jehan.com
    Licence: GPL2
   */
  
  add_theme_support('post-thumbnails');
  
  add_action('init', 'owlcarousel_init');
  add_action('wp_print_scripts', 'owl_register_scripts');
  add_action('wp_print_styles', 'owl_register_styles');
  add_action('widgets_init', 'owl_widgets_init');
  add_action('manage_edit-owl-carousel_columns', 'owl_columnfilter');
  add_action('manage_posts_custom_column', 'owl_column');
  add_action('admin_menu', 'owl_carousel_menu');
  add_action('admin_enqueue_scripts', 'owl_carousel_admin_register_scripts');
  
  if (filter_var(get_option('owl_carousel_wordpress_gallery', false), FILTER_VALIDATE_BOOLEAN)) {
      add_filter('post_gallery', 'owl_carousel_post_gallery', 10, 2);
  }
  
  // Add functions to create a new attachments fields
  add_filter("attachment_fields_to_edit", "owl_carousel_attachment_fields_to_edit", null, 2);
  add_filter("attachment_fields_to_save", "owl_carousel_attachment_fields_to_save", null, 2);
  
  /**
   * Initilize the plugin
   */
  function owlcarousel_init() {
  
      $labels = array(
          'name' =&gt; __('Owl Carousel', 'owl-carousel-domain'),
          'singular_name' =&gt; __('Carousel Slide', 'owl-carousel-domain'),
          'add_new' =&gt; __('Add New Slide', 'owl-carousel-domain'),
          'add_new_item' =&gt; __('Add New Carousel Slide', 'owl-carousel-domain'),
          'edit_item' =&gt; __('Edit Carousel Slide', 'owl-carousel-domain'),
          'new_item' =&gt; __('Add New Carousel Slide', 'owl-carousel-domain'),
          'view_item' =&gt; __('View Slide', 'owl-carousel-domain'),
          'search_items' =&gt; __('Search Carousel', 'owl-carousel-domain'),
          'not_found' =&gt; __('No carousel slides found', 'owl-carousel-domain'),
          'not_found_in_trash' =&gt; __('No carousel slides found in trash', 'owl-carousel-domain'),
      );
  
      register_post_type('owl-carousel', array(
          'public' =&gt; true,
          'publicly_queryable' =&gt; false,
          'exclude_from_search' =&gt; true,
          'label' =&gt; 'Owl Carousel',
          'menu_icon' =&gt; plugins_url('/owl-carousel/images/owl-logo-16.png'),
          'labels' =&gt; $labels,
          'capability_type' =&gt; 'post',
          'supports' =&gt; array(
              'title',
              'editor',
              'thumbnail'
          )
      ));
  
      $taxonomy_labels = array(
          'name' =&gt; __('Carousels', 'owl-carousel-domain'),
          'singular_name' =&gt; __('Carousel', 'owl-carousel-domain'),
          'search_items' =&gt; __('Search Carousels', 'owl-carousel-domain'),
          'popular_items' =&gt; __('Popular Carousels', 'owl-carousel-domain'),
          'all_items' =&gt; __('All Carousels', 'owl-carousel-domain'),
          'parent_item' =&gt; null,
          'parent_item_colon' =&gt; null,
          'edit_item' =&gt; __('Edit Carousel', 'owl-carousel-domain'),
          'update_item' =&gt; __('Update Carousel', 'owl-carousel-domain'),
          'add_new_item' =&gt; __('Add New Carousel', 'owl-carousel-domain'),
          'new_item_name' =&gt; __('New Carousel Name', 'owl-carousel-domain'),
          'separate_items_with_commas' =&gt; __('Separate carousels with commas', 'owl-carousel-domain'),
          'add_or_remove_items' =&gt; __('Add or remove carousels', 'owl-carousel-domain'),
          'choose_from_most_used' =&gt; __('Choose from the most used carousels', 'owl-carousel-domain'),
          'not_found' =&gt; __('No carousels found.', 'owl-carousel-domain'),
          'menu_name' =&gt; __('Carousels', 'owl-carousel-domain'),
      );
  
      register_taxonomy('Carousel', 'owl-carousel', array(
          'labels' =&gt; $taxonomy_labels,
          'rewrite' =&gt; array('slug' =&gt; 'carousel'),
          'hierarchical' =&gt; true,
          'show_admin_column' =&gt; true,
      ));
  
      add_image_size('owl_widget', 180, 100, true);
      add_image_size('owl_function', 600, 280, true);
  
      add_shortcode('owl-carousel', 'owl_function');
      add_filter("mce_external_plugins", "owl_register_tinymce_plugin");
      add_filter('mce_buttons', 'owl_add_tinymce_button');
  
      // Add Wordpress Gallery option
      add_option('owl_carousel_wordpress_gallery', 'off');
      add_option('owl_carousel_orderby', 'post_date');
  }
  
  function owl_carousel_menu() {
      add_submenu_page('edit.php?post_type=owl-carousel', __('Parameters', 'owl-carousel-domain'), __('Parameters', 'owl-carousel-domain'), 'manage_options', 'owl-carousel-parameters', 'submenu_parameters');
  }
  
  function submenu_parameters() {
  
      $isWordpressGallery = (filter_var(get_option('owl_carousel_wordpress_gallery', false), FILTER_VALIDATE_BOOLEAN)) ? 'checked' : '';
      $orderBy = get_option('owl_carousel_orderby', 'post_date');
      $orderByOptions = array('post_date', 'title');
  
      echo '&lt;div class="wrap owl_carousel_page"&gt;';
  
      echo '&lt;?php update_option("owl_carousel_wordpress_gallery", $_POST["wordpress_gallery"]); ?&gt;';
  
      echo '&lt;h2&gt;' . __('Owl Carousel parameters', 'owl-carousel-domain') . '&lt;/h2&gt;';
  
      echo '&lt;form action="' . plugin_dir_url(__FILE__) . 'save_parameter.php" method="POST" id="owlcarouselparameterform"&gt;';
  
      echo '&lt;h3&gt;' . __('Wordpress Gallery', 'owl-carousel-domain') . '&lt;/h3&gt;';
      echo '&lt;input type="checkbox" name="wordpress_gallery" ' . $isWordpressGallery . ' /&gt;';
      echo '&lt;label&gt;' . __('Use Owl Carousel with Wordpress Gallery', 'owl-carousel-domain') . '&lt;/label&gt;';
      echo '&lt;br /&gt;';
      echo '&lt;label&gt;' . __('Order Owl Carousel elements by ', 'owl-carousel-domain') . '&lt;/label&gt;';
      echo '&lt;select name="orderby" /&gt;';
      foreach ($orderByOptions as $option) {
          echo '&lt;option value="' . $option . '" ' . (($option == $orderBy) ? 'selected="selected"' : '') . '&gt;' . $option . '&lt;/option&gt;';
      }
      echo '&lt;/select&gt;';
      echo '&lt;br /&gt;';
      echo '&lt;br /&gt;';
      echo '&lt;input type="submit" class="button-primary owl-carousel-save-parameter-btn" value="' . __('Save changes', 'owl-carousel-domain') . '" /&gt;';
      echo '&lt;span class="spinner"&gt;&lt;/span&gt;';
  
      echo '&lt;/form&gt;';
  
      echo '&lt;/div&gt;';
  }
  
  /**
   * List of JavaScript / CSS files for admin
   */
  function owl_carousel_admin_register_scripts() {
      wp_register_style('owl.carousel.admin.styles', plugin_dir_url(__FILE__) . 'css/admin_styles.css');
      wp_enqueue_style('owl.carousel.admin.styles');
  
      wp_register_script('owl.carousel.admin.script', plugin_dir_url(__FILE__) . 'js/admin_script.js');
      wp_enqueue_script('owl.carousel.admin.script');
  }
  
  /**
   * List of JavaScript files
   */
  function owl_register_scripts() {
      wp_register_script('js.owl.carousel', plugins_url('/owl-carousel/js/owl.carousel.js'));
      wp_register_script('js.owl.carousel.script', plugins_url('/owl-carousel/js/script.js'));
  
      wp_enqueue_script('jquery');
      wp_enqueue_script('js.owl.carousel');
      wp_enqueue_script('js.owl.carousel.script');
  }
  
  /**
   * List of CSS files
   */
  function owl_register_styles() {
      wp_register_style('style.owl.carousel', plugins_url('/owl-carousel/css/owl.carousel.css'));
      wp_register_style('style.owl.carousel.theme', plugins_url('/owl-carousel/css/owl.theme.css'));
      wp_register_style('style.owl.carousel.transitions', plugins_url('/owl-carousel/css/owl.transitions.css'));
      wp_register_style('style.owl.carousel.styles', plugins_url('/owl-carousel/css/styles.css'));
  
      wp_enqueue_style('style.owl.carousel');
      wp_enqueue_style('style.owl.carousel.theme');
      wp_enqueue_style('style.owl.carousel.transitions');
      wp_enqueue_style('style.owl.carousel.styles');
  }
  
  function owl_register_tinymce_plugin($plugin_array) {
      $plugin_array['owl_button'] = plugins_url('/owl-carousel/js/owl-tinymce-plugin.js');
      return $plugin_array;
  }
  
  function owl_add_tinymce_button($buttons) {
      $buttons[] = "owl_button";
      return $buttons;
  }
  
  /*
   * Initialize Owl Widget
   */
  
  function owl_widgets_init() {
      register_widget("owl_Widget");
  }
  
  class owl_Widget extends WP_Widget {
  
      public function __construct() {
          parent::__construct('owl_Widget', 'Owl Carousel', array('description' =&gt; __('A Owl Carousel Widget', 'text_domain')));
      }
  
      public function form($instance) {
          if (isset($instance['title'])) {
              $title = $instance['title'];
          } else {
              $title = __('Widget Carousel', 'text_domain');
          }
          if (isset($instance['category'])) {
              $carousel = $instance['category'];
          } else {
              $carousel = 'Uncategorized';
          }
          ?&gt;
          &lt;p&gt;
              &lt;label for="&lt;?php echo $this-&gt;get_field_id('title'); ?&gt;"&gt;&lt;?php _e('Title:'); ?&gt;&lt;/label&gt;
              &lt;input class="widefat" id="&lt;?php echo $this-&gt;get_field_id('title'); ?&gt;" name="&lt;?php echo $this-&gt;get_field_name('title'); ?&gt;" type="text" value="&lt;?php echo esc_attr($title); ?&gt;" /&gt;
          &lt;/p&gt;
          &lt;p&gt;
              &lt;label for="&lt;?php echo $this-&gt;get_field_id('category'); ?&gt;"&gt;&lt;?php _e('Carousel:'); ?&gt;&lt;/label&gt;
              &lt;input class="widefat" id="&lt;?php echo $this-&gt;get_field_id('category'); ?&gt;" name="&lt;?php echo $this-&gt;get_field_name('category'); ?&gt;" type="text" value="&lt;?php echo esc_attr($carousel); ?&gt;" /&gt;
          &lt;/p&gt;
          &lt;?php
      }
  
      public function update($new_instance, $old_instance) {
          $instance = array();
          $instance['title'] = strip_tags($new_instance['title']);
          $instance['category'] = strip_tags($new_instance['category']);
  
          return $instance;
      }
  
      public function widget($args, $instance) {
          extract($args);
          $title = apply_filters('widget_title', $instance['title']);
          echo $before_widget;
          if (!empty($title))
              echo $before_title . $title . $after_title;
          echo owl_function(array(category =&gt; $instance['category'], singleItem =&gt; "true", autoPlay =&gt; "true", pagination =&gt; "false"));
          echo $after_widget;
      }
  
  }
  
  /**
   * Add custom column filters in administration
   * @param array $columns
   */
  function owl_columnfilter($columns) {
      $thumb = array('thumbnail' =&gt; 'Image');
      $columns = array_slice($columns, 0, 2) + $thumb + array_slice($columns, 2, null);
  
      return $columns;
  }
  
  /**
   * Add custom column contents in administration
   * @param string $columnName
   */
  function owl_column($columnName) {
      global $post;
      if ($columnName == 'thumbnail') {
          echo edit_post_link(get_the_post_thumbnail($post-&gt;ID, 'thumbnail'), null, null, $post-&gt;ID);
      }
  }
  
  /**
   * Adding our images custom fields to the $form_fields array
   * @param array $form_fields
   * @param object $post
   * @return array
   */
  function owl_carousel_attachment_fields_to_edit($form_fields, $post) {
      // add our custom field to the $form_fields array
      // input type="text" name/id="attachments[$attachment-&gt;ID][custom1]"
      $form_fields["owlurl"] = array(
          "label" =&gt; __("Owl Carousel URL"),
          "input" =&gt; "text",
          "value" =&gt; get_post_meta($post-&gt;ID, "_owlurl", true)
      );
  
      return $form_fields;
  }
  
  /**
   * Save images custom fields
   * @param array $post
   * @param array $attachment
   * @return array
   */
  function owl_carousel_attachment_fields_to_save($post, $attachment) {
      if (isset($attachment['owlurl'])) {
          update_post_meta($post['ID'], '_owlurl', $attachment['owlurl']);
      }
  
      return $post;
  }
  
  /**
   * Plugin main function
   * @param type $atts Owl parameters
   * @param type $content
   * @return string Owl HTML code
   */
  function owl_function($atts, $content = null) {
      extract(shortcode_atts(array(
          'category' =&gt; 'Uncategoryzed'
                      ), $atts));
  
      $data_attr = "";
      foreach ($atts as $key =&gt; $value) {
          if ($key != "category") {
              $data_attr .= ' data-' . $key . '="' . $value . '" ';
          }
      }
  
      $lazyLoad = array_key_exists("lazyload", $atts) &amp;&amp; $atts["lazyload"] == true;
  
      $args = array(
          'post_type' =&gt; 'owl-carousel',
          'orderby' =&gt; get_option('owl_carousel_orderby', 'post_date'),
          'order' =&gt; 'asc',
          'tax_query' =&gt; array(
              array(
                  'taxonomy' =&gt; 'Carousel',
                  'field' =&gt; 'slug',
                  'terms' =&gt; $atts['category']
              )
          ),
          'nopaging' =&gt; true
      );
  
   $result = '&lt;div id="owl-carousel-' . rand() . '" class="owl-carousel owl-carousel-' . sanitize_title($atts['category']) . '" ' . $data_attr . '&gt;';
  
      $loop = new WP_Query($args);
      while ($loop-&gt;have_posts()) {
          $loop-&gt;the_post();
  
          $img_src = wp_get_attachment_image_src(get_post_thumbnail_id(get_the_ID()), get_post_type());
          $meta_link = get_post_meta(get_post_thumbnail_id(get_the_ID()), '_owlurl', true);
  
          $result .= '&lt;div class="item"&gt;';
          if ($img_src[0]) {
              $result .= '&lt;div&gt;';
              if (!empty($meta_link)) {
                  $result .= '&lt;a href="' . $meta_link . '"&gt;';
              }
              if ($lazyLoad) {
                  $result .= '&lt;img class="lazyOwl" title="' . get_the_title() . '" data-src="' . $img_src[0] . '" alt="' . get_the_title() . '"/&gt;';
              } else {
                  $result .= '&lt;img title="' . get_the_title() . '" src="' . $img_src[0] . '" alt="' . get_the_title() . '"/&gt;';
              }
              if (!empty($meta_link)) {
                  $result .= '&lt;/a&gt;';
              }
  
              // Add image overlay with hook
              $slide_title = get_the_title();
              $slide_content = get_the_content();
              $img_overlay = '&lt;div class="owl-carousel-item-imgoverlay"&gt;';
              $img_overlay .= '&lt;div class="owl-carousel-item-imgtitle"&gt;' . $slide_title . '&lt;/div&gt;';
              $img_overlay .= '&lt;div class="owl-carousel-item-imgcontent"&gt;' . wpautop($slide_content) . '&lt;/div&gt;';
              $img_overlay .= '&lt;/div&gt;';
              $result .= apply_filters('owlcarousel_img_overlay', $img_overlay, $slide_title, $slide_content, $meta_link);
  
              $result .= '&lt;/div&gt;';
          } else {
              $result .= '&lt;div class="owl-carousel-item-text"&gt;' . get_the_content() . '&lt;/div&gt;';
          }
          $result .= '&lt;/div&gt;';
      }
      $result .= '&lt;/div&gt;';
      
      /* Restore original Post Data */
      wp_reset_postdata();
  
      return $result;
  }
  
  /**
   * Owl Carousel for Wordpress image gallery
   * @param string $output Gallery output
   * @param array $attr Parameters
   * @return string Owl HTML code
   */
  function owl_carousel_post_gallery($output, $attr) {
      global $post;
  
      if (isset($attr['orderby'])) {
          $attr['orderby'] = sanitize_sql_orderby($attr['orderby']);
          if (!$attr['orderby'])
              unset($attr['orderby']);
      }
  
      extract(shortcode_atts(array(
          'order' =&gt; 'ASC',
          'orderby' =&gt; 'menu_order ID',
          'id' =&gt; $post-&gt;ID,
          'itemtag' =&gt; 'dl',
          'icontag' =&gt; 'dt',
          'captiontag' =&gt; 'dd',
          'columns' =&gt; 3,
          'size' =&gt; 'thumbnail',
          'include' =&gt; '',
          'exclude' =&gt; ''
                      ), $attr));
  
      $id = intval($id);
      if ('RAND' == $order)
          $orderby = 'none';
  
      if (!empty($include)) {
          $include = preg_replace('/[^0-9,]+/', '', $include);
          $_attachments = get_posts(array('include' =&gt; $include, 'post_status' =&gt; 'inherit', 'post_type' =&gt; 'attachment', 'post_mime_type' =&gt; 'image', 'order' =&gt; $order, 'orderby' =&gt; $orderby));
  
          $attachments = array();
          foreach ($_attachments as $key =&gt; $val) {
              $attachments[$val-&gt;ID] = $_attachments[$key];
          }
      }
  
      if (empty($attachments))
          return '';
  
  
      // Add item number if not defined
      if (!isset($attr['items'])) {
          $attr['items'] = '1';
      }
  
      $data_attr = "";
      foreach ($attr as $key =&gt; $value) {
          if ($key != "category") {
              $data_attr .= ' data-' . $key . '="' . $value . '" ';
          }
      }
  
      $output .= '&lt;div id="owl-carousel-' . rand() . '" class="owl-carousel" ' . $data_attr . '&gt;';
  
      foreach ($attachments as $id =&gt; $attachment) {
          $img = wp_get_attachment_image_src($id, 'full');
          $meta_link = get_post_meta($id, '_owlurl', true);
  
          $title = $attachment-&gt;post_title;
  
          $output .= "&lt;div class=\"item\"&gt;";
          if (!empty($meta_link)) {
              $output .= "&lt;a href=\"" . $meta_link . "\"&gt;";
          }
          $output .= "&lt;img src=\"{$img[0]}\" width=\"{$img[1]}\" height=\"{$img[2]}\" alt=\"$title\" /&gt;\n";
          if (!empty($meta_link)) {
              $output .= "&lt;/a&gt;";
          }
          $output .= "&lt;/div&gt;";
      }
  
      $output .= "&lt;/div&gt;";
  
      return $output;
  }</code></pre>
  </div>
  </div>
  </p>
  
  <p>what I'm trying to get the carousel to look like (whowhatwear.com)
  <a href="https://i.stack.imgur.com/P0EGj.png" rel="noreferrer"><img src="https://i.stack.imgur.com/P0EGj.png" alt="enter image description here"></a></p>
  
  <p>Would I want my code to look something like this?</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;div id="slider"&gt; 
  &lt;?php 
  $carousel_cat = get_theme_mod('carousel_setting','1'); 
  $carousel_count = get_theme_mod('count_setting','4'); 
  $month = date('m'); 
  $year = date('Y'); 
  $new_query = new WP_Query( array('posts_per_page' =&gt; $carousel_count, 'meta_key' =&gt; 'wpb_post_views_count', 'orderby' =&gt; 'meta_value_num', 'order' =&gt; 'DESC','monthnum'=&gt;$month,'year'=&gt;$year )); 
  ?&gt; 
  &lt;?php if ( $new_query-&gt;have_posts() ) : ?&gt; 
  &lt;?php while ( $new_query-&gt;have_posts() ) : $new_query-&gt;the_post(); ?&gt; 
  &lt;div class="item"&gt; 
      &lt;?php the_post_thumbnail('popular-posts'); ?&gt;
      &lt;h2&gt;&lt;a class="popular-category" 
          &lt;?php 
  $categories = get_the_category();
  if ( ! empty( $categories ) ) {
      echo '&lt;a href="' . esc_url( get_category_link( $categories[0]-&gt;term_id ) ) . '"&gt;' . esc_html( $categories[0]-&gt;name ) . '&lt;/a&gt;';
  }
          
          ?&gt;&lt;/a&gt;&lt;/h2&gt;
   &lt;p&gt;
       &lt;a class="popular-excerpt" href="&lt;?php the_permalink(); ?&gt;"&gt;&lt;?php echo get_the_excerpt(); ?&gt;&lt;/a&gt;
                  &lt;/p&gt;
  &lt;/div&gt; 
  &lt;?php endwhile; wp_reset_postdata(); ?&gt; 
  &lt;?php else : ?&gt; 
  &lt;p&gt;&lt;?php _e(); ?&gt;&lt;/p&gt; 
  &lt;?php endif; ?&gt; 
  &lt;/div&gt;</code></pre>
  </div>
  </div>
  </p>