Last active
September 17, 2017 03:31
-
-
Save alandbh/46a0afe4051bfa7f52e2545436170f0a to your computer and use it in GitHub Desktop.
shortcode for embeding youtube videos
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
---------- 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')); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment