0

I have inserted a shortcode in functions.php file. The shorcode is :

function multi_carousel_random_shortcode($atts){ extract( shortcode_atts( array( 'post_type' => 'carousel-item', ), $atts ) );

    $q = new WP_Query(
        array('posts_per_page' => -1, 'post_type' => $post_type)     
        );      
    $list = '

    <script>
    jQuery(document).ready(function() {
      jQuery("#owl-demo-eleven").owlCarousel({
            navigation: true,
            navigationText: ["<i class=fa fa-angle-left></i>","<i class='fa fa-angle-right'></i>"],
          });
        });
    </script>       
    <div id="owl-demo-eleven" class="owl-carousel owl-theme">
    ';
    while($q->have_posts()) : $q->the_post();
        $idd = get_the_ID();
        $carousel_img = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID), 'carousel-small' );

        $list .= '
        <div class="item"><img src="'.$carousel_img[0].'" alt="" /></div>   
    ';        
    endwhile;
    $list.= '
    </div>
    ';
    wp_reset_query();
    return $list;
}
add_shortcode('multi_carousel_random', 'multi_carousel_random_shortcode');

All things are ok, but 'icon code' in navigationText is producing error. Do you have any solution to overcome the problem?

masud
  • 1
  • 3

1 Answers1

0

navigationText: ["<i class=fa fa-angle-left></i>","<i class='fa fa-angle-right'></i>"], is not escaped properly.

When you have a string defined by ', any time there is another ' that does not define the end of the string, you have to escape it using \' to tell the program that this is not an end of string.

Should be:

navigationText: ["<i class=\'fa fa-angle-left\'></i>","<i class=\'fa fa-angle-right\'></i>"],

Carl K
  • 904
  • 6
  • 17