【问题标题】:Wordpress editor shortcode for custom html ouput用于自定义 html 输出的 Wordpress 编辑器简码
【发布时间】:2016-02-25 01:31:56
【问题描述】:

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

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

【问题讨论】:

    标签: php wordpress


    【解决方案1】:

    在你的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"]
    

    【讨论】:

      【解决方案2】:

      试试这个

      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');
      

      [youtube_iframe id='some_id']一样使用

      供参考:add_shortcodeshortcode_atts

      【讨论】:

        猜你喜欢
        • 2014-07-27
        • 1970-01-01
        • 2013-01-29
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2018-03-31
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多