【问题标题】:Wordpress Stripping HTML5 Playsinline From VideosWordpress 从视频中剥离 HTML5 Playsinline
【发布时间】:2019-10-19 21:22:07
【问题描述】:

我在我的 Wordpress 网站上有一些视频已静音并自动播放,但 Wordpress 不断从代码中剥离 playinline,破坏了移动设备上的自动播放功能。

<video playsinline="playsinline" autoplay="autoplay" loop="loop" muted="muted" width="240" height="520"> <source src="https://storage.googleapis.com/example.mp4" type="video/mp4" /</video>

有谁知道如何防止 Wordpress 在切换到可视化编辑器模式时从代码中删除playsinline="playsinline"

【问题讨论】:

    标签: html wordpress video html5-video strip


    【解决方案1】:

    我相信您没有使用 Gutenberg 更新的 wordpress 编辑器。 在gutenberg 中,您可以放置​​html 代码块并且它们不会被wp 编辑器更改;

    在之前的 wordpress 版本中,您需要通过 functions.php 传递代码 在您的functions.php 中输入以下代码:

    // stop wp removing especifics tags
    function bz_uncoverwp_tiny_mce( $init )
    {
        // html elements being stripped
        //put here any other tags in this same form
        $init['extended_valid_elements'] = 'video[*], source[*], div[*], articles';
    
        // don't remove line breaks
        $init['remove_linebreaks'] = false;
    
        // convert newline characters to BR
        $init['convert_newlines_to_brs'] = true;
    
        // don't remove redundant BR
        $init['remove_redundant_brs'] = false;
    
        // pass back to wordpress
        return $init;
    }
    add_filter( 'tiny_mce_before_init', 'bz_uncoverwp_tiny_mce' );
    

    我在代码中留下了一些您可能感兴趣的技巧;)

    【讨论】:

    • 那太好了,唯一的另一件事是我有一个自定义按钮调用 js。这是按钮<button id="convertButton" onclick="copyToClipboard('.instacopy')" data-text-swap="Copied!">Copy The Text</button> 我在video[*] 之后添加了button[*],但这似乎并没有阻止Wordpress 在切换到可视化编辑器时删除onclick="copyToClipboard('.instacopy')"。有什么想法让 Wordpress 也不会删除它吗?
    猜你喜欢
    • 2010-10-10
    • 1970-01-01
    • 2013-06-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-11-12
    • 2017-11-12
    相关资源
    最近更新 更多