alandbh
9/9/2017 - 8:45 PM

shortcode for embeding youtube videos

shortcode for embeding youtube videos

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

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

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

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

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

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

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