Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/wordpress/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 自定义html输出的Wordpress编辑器短代码_Php_Wordpress - Fatal编程技术网

Php 自定义html输出的Wordpress编辑器短代码

Php 自定义html输出的Wordpress编辑器短代码,php,wordpress,Php,Wordpress,我需要帮助创建Wordpress函数,使post editor中的shortcode[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($att

我需要帮助创建Wordpress函数,使post editor中的shortcode
[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');
试试这个

function my_amazing_shortcode_handler($args)
{
    $args=shortcode_atts(array('id' => 'some_default_id'), $args);
    return '<iframe width="420" height="315" src="https://www.youtube.com/embed/' . $args['id'] . '?rel=0" frameborder="0" allowfullscreen></iframe>';
}

add_shortcode('youtube_iframe', 'my_amazing_shortcode_handler');
函数my_Aspective_shortcode_处理程序($args)
{
$args=shortcode_atts(数组('id'=>'some_default_id'),$args);
返回“”;
}
添加快捷代码(“youtube iframe”、“我的快捷代码处理程序”);
使用类似于
[youtube\u iframe id='some\u id']

供参考:

function my_amazing_shortcode_handler($args)
{
    $args=shortcode_atts(array('id' => 'some_default_id'), $args);
    return '<iframe width="420" height="315" src="https://www.youtube.com/embed/' . $args['id'] . '?rel=0" frameborder="0" allowfullscreen></iframe>';
}

add_shortcode('youtube_iframe', 'my_amazing_shortcode_handler');