Wordpress 剥离 HTML5 从视频中在线播放

Wordpress Stripping HTML5 Playsinline From Videos

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

<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"

我相信您使用的不是 Gutenberg 更新后的 wordpress 编辑器。 在古腾堡中,您可以放置​​ 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' );

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