¿Está buscando una forma de ajustar el ancho/alto del iframe de video auto-incrustado de Vimeo? Si bien probablemente exista un plugin para esto, hemos creado un fragmento de código rápido que puede usar para ajustar el tamaño de las auto-incrustaciones de Vimeo en WordPress. Asegúrese de que su sitio de WordPress tenga habilitadas las auto-incrustaciones.
Instrucciones:
Todo lo que tienes que hacer es agregar este código al archivo functions.php de tu tema o a un plugin específico del sitio:
function fixEmbed($oembvideo, $url, $attr) {
if(strpos($url,'vimeo.com')!== false) {
// check if url is for Vimeo video
$width = 0;
$height = 0;
$newheight = 0;
$attrstart = strpos($oembvideo,'width="');
if($attrstart !== false) {
$attrstart += 7;
$width = substr($oembvideo, $attrstart, strpos($oembvideo,'"',$attrstart+1)-$attrstart);
$attrstart = strpos($oembvideo,'height="');
if(($attrstart !== false) && $width>0) {
$attrstart += 8;
$height = substr($oembvideo, $attrstart, strpos($oembvideo,'"',$attrstart+1)-$attrstart);
$newheight = round($height*$attr['width']/$width);
$oembvideo = str_replace('height="'.$height,'height="'.$newheight, str_replace('width="'.$width,'width="'.$attr['width'], $oembvideo));
}
}
}
return $oembvideo;
}
add_filter('embed_oembed_html', 'fixEmbed', 10, 3);
Nota: Si es la primera vez que agregas fragmentos de código en WordPress, consulta nuestra guía sobre cómo agregar fragmentos de código correctamente en WordPress, para que no rompas accidentalmente tu sitio.
Si le gustó este fragmento de código, considere revisar nuestros otros artículos en el sitio como: 19 mejores plugins de WordPress para organizaciones sin fines de lucro y cómo crear un formulario de varias páginas en WordPress.
Comentarios Dejar una respuesta