php Shortcode para video do youtube

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了php Shortcode para video do youtube相关的知识,希望对你有一定的参考价值。



/*
----------  Shortcode de Video
            Alan
*/
class short_youtube {
    function shortcode($atts, $content = null)
    {
        
        extract(shortcode_atts(array(
            'alinhamento' => '',
            'id' => '',
            'link' => '',
        ), $atts));

        $classeResponsive = '';
        $classeResponsiveItem = '';

        if (!$alinhamento) {
          $posicao = 'float:left;margin: 0 1.5em 1.5em 0;';

        } elseif ($alinhamento == 'direita') {
          $posicao = 'float:right;margin: 0 0 1.5em 1.5em;';

        } elseif ($alinhamento == 'centro') {
          $posicao = 'margin: 1.5em auto;text-align: center;';

        } elseif ($alinhamento == 'total') {
          $posicao = 'margin: 1.5em auto;'; 
          $classeResponsive = 'embed-responsive embed-responsive-16by9';
          $classeResponsiveItem = 'embed-responsive-item';
        }

        if (!$alinhamento):
          $alinhamento = 'left';
        endif;

        $src = str_replace("watch?v=","embed/",$link);

        $youtubeDom = '';
        $youtubeDom .= '<div style="' . $posicao . '" class="' . $classeResponsive . '">';
        $youtubeDom .= '<iframe class="' . $classeResponsiveItem . '" width="560" height="315" src="' . $src . '" frameborder="0" allowfullscreen></iframe>';
        $youtubeDom .= '</div>';

        return
            "
                $youtubeDom

            "
            ;
    }
}

add_shortcode('youtube', array('short_youtube', 'shortcode'));


以上是关于php Shortcode para video do youtube的主要内容,如果未能解决你的问题,请参考以下文章

php SHORTCODE:将“类型”字段修剪为“字数”

php 媒体查询ShortCode

php WP Shortcode加载远程内容

php 如何在Blooming中启用Shortcode

php semplice shortcode con contenuto

php WordPress Shortcode返回当前页面标题。