在WooCommerce嵌入Kingsway视频

当我们在WooCommerce中嵌入Kingsway视频时,我会碰到一些问题,下面的内容将帮助你解决:

1. 原因

WordPress自动对内容做了过滤和格式化导致的。

在 WooCommerce 的 product description(商品描述)里,WordPress 默认会把内容当作“post content”处理,而 wpautop 和 wp_kses 这些函数会把 <script> 包起来,甚至直接过滤掉。

2. 解决方法

1. 安装Code Snippets插件

在wordpress后台安装Code Snippets插件,这个是一个免费的,非常安全和稳定的,下载和安装量超过100万的插件。

2. 添加代码

Snippet Title那里可以填写(这个信息你可以随意填写):

allow script tags in video_embed_code

Snippet Content那里填写:

function allow_script_in_description($tags) {
    $tags['script'] = array(
        'type' => true,
        'src'  => true,
        'async' => true,
        'defer' => true
    );
    return $tags;
}
add_filter('wp_kses_allowed_html', 'allow_script_in_description', 10, 2);
function disable_wpautop_on_products($content) {
    if (is_singular('product')) {
        remove_filter('the_content', 'wpautop');
        remove_filter('the_content', 'wptexturize');
    }
    return $content;
}
add_filter('the_content', 'disable_wpautop_on_products', 0);

3. 保存并测试

保存后即可,然后可以去到之前内嵌了Kingsway的视频的页面进行查看。

目录

14天全部功能免费试用

点击按钮后你将跳转到Kingsway的注册页面,注册后就可以免费试用了。

让每一个视频都为你赢得商业机会,让每一次播放都为你带来价值。

售前咨询 & 普通咨询

另外,我们已经准备了一个帮助中心,建议你在联系之前先看看,也许你的问题和答案都已经在那里清楚说明了。

让你在视频中拿到询盘

点击按钮后跳转到Kingsway英文官网的注册页面,你注册后在页面右上角点击upgrade按钮可以进行支付了。

让每一个视频都为你赢得商业机会,让每一次播放都为你带来询盘价值。