首页 > 解决方案 > 如何将 ShortCode 转换为 Gutenberg Block?

问题描述

我在functions.php中有简码:

function video( $atts, $content = null ) {
        return '<div class="videoWrapper"><iframe width="1280" height="720" src="https://www.youtube.com/embed/' .$content. '" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe></div>';
}

add_shortcode( 'video', 'video' );

我用它作为:

[video]videoID[/video]

输出是:

<div class="videoWrapper">
<iframe width="1280" height="720" src="https://www.youtube.com/embed/videoID" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen>
</iframe>
</div>

我有奇怪的键盘,我不知道如何输入[],所以每当我需要它时,我需要谷歌它或打开现有帖子以复制它并发布短代码,所以如果我可以预定义古腾堡块会容易得多点击添加[video]videoID[/video][video="videoID"]

标签: phpwordpressshortcode

解决方案


推荐阅读