alandbh
9/9/2017 - 8:22 PM

Shortcode para video do youtube

Add a shortcode for embeding youtube video in page



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