You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

WordPress中Slick滑块随机生成<p>标签导致轮播空白的问题求助

WordPress中Slick滑块随机生成

标签导致轮播空白的问题求助

各位好,我在WordPress里做了一个Slick滑块,用来展示WooCommerce的产品图片,还给这个功能写了个短代码。但现在遇到个麻烦:滑块里会随机在图片之间插入<p>标签,导致轮播出现空白区域。

我已经尝试用下面这两个过滤器来移除自动添加的段落标签,但完全没效果:

remove_filter( 'the_content', 'wpautop' );
remove_filter( 'the_excerpt', 'wpautop' );

下面是我的短代码函数代码,麻烦大家帮忙看看问题出在哪:

function product_images_slick_carousel_shortcode() {

ob_start(); ?>

<div class="product-images">

<?php

global $product;

$attachment_ids = $product->get_gallery_image_ids();

if ($attachment_ids) {

foreach ($attachment_ids as $attachment_id) {

$image_url = wp_get_attachment_url($attachment_id);

if ($image_url) {

echo '<div><img src="' . esc_url($image_url) . '"></div>';

}

}

} else {

$thumbnail_id = get_post_thumbnail_id($product->get_id());

$thumbnail_url = wp_get_attachment_url($thumbnail_id);

if ($thumbnail_url) {

echo '<div><img src="' . esc_url($thumbnail_url) . '"></div>';

}

}

?>

</div>

<script>

jQuery(document).ready(function ($) {

$('.product-images').slick({

// Slick carousel options

autoplay: true,

autoplaySpeed: 4000,

arrows: true,

slidesToShow: 4,

slidesToScroll: 1

// Add more options as needed

});

});

</script>

<?php

return ob_get_clean();

}

add_shortcode('product_images_slick_carousel', 'product_images_slick_carousel_shortcode');

有没有大佬知道这是怎么回事呀?

备注:内容来源于stack exchange,提问作者user2407147

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.20 09:28:06