Skip to content

Instantly share code, notes, and snippets.

@alandbh
Last active September 17, 2017 03:31
Show Gist options
  • Save alandbh/46a0afe4051bfa7f52e2545436170f0a to your computer and use it in GitHub Desktop.
Save alandbh/46a0afe4051bfa7f52e2545436170f0a to your computer and use it in GitHub Desktop.
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'));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment