php - 用于自定义 html 输出的 Wordpress 编辑器简码

标签 php wordpress

我需要帮助创建 Wordpress 函数以在后期编辑器中生成短代码 [youtube-id=ID] 输出以下包含 ID 值的 html 代码:

<iframe width="420" height="315" src="https://www.youtube.com/embed/ID?rel=0" frameborder="0" allowfullscreen></iframe>

最佳答案

在你的 functions.php 中

function YouTubeID($atts, $content = null) {
    extract(shortcode_atts(array('id'=>''), $atts));
    return '<iframe width="420" height="315" src="https://www.youtube.com/embed/'.$id.'?rel=0" frameborder="0" allowfullscreen></iframe>';
}
add_shortcode('youtube', 'YouTubeID');

无论您想要视频的哪个位置,短代码都将是:

[youtube id="THE_ID"]

关于php - 用于自定义 html 输出的 Wordpress 编辑器简码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35608773/

相关文章:

php - MySQL Where 子句错误

php - 重写完整的项目有用吗?了解建立主页的想法

wordpress - 仅为特定管理页面加载脚本

php - WooCommerce 添加到购物车验证 : prevent add to cart

javascript - 粒子js无法正常工作

php - 如果未登录,Wordpress 会重定向用户

php - 错误的T-SQL查询时sqlsrv_query不会返回false

javascript - 在 node.js 中使用存储在 Memcached 中的 php 数组

php - 如何制作国家/地区特定网站(和内容)?

mysql - WordPress 数据库错误 - _wp_plugin_attachment_metadata