这就是我精心设计来覆盖默认值的内容,我设置了默认的媒体宽度,选择纵横比(16:9),然后替换视频短码输出。
$defaultMediaWidth = 960;
if ( ! isset( $content_width ) ) {
$content_width = $defaultMediaWidth;
}
add_filter( \'embed_defaults\', \'bigger_embed_size\');
function bigger_embed_size()
{
global $content_width;
$width = $content_width;
// aspect ratio 16:9
$r1 = 16;
$r2 = 9;
$r = $width / $r1;
$height = $r * $r2;
return array( \'width\' => $width, \'height\' => $height );
}
function EMP_video_shortcode_override(
$output = \'\',
$atts = [],
$video = \'\',
$post_id = 0,
$library = \'\'
){
$defaults = wp_embed_defaults();
$searchfor = [
\'width="\' . $atts[\'width\'] . \'"\',
\'width: \' . $atts[\'width\'] . \'px;\',
\'height="\' . $atts[\'height\'] . \'"\'
];
$replaceto = [
\'width="\' . $defaults[\'width\'] . \'"\',
\'width:\' . $defaults[\'width\'] . \'px;\',
\'height="\' . $defaults[\'height\'] . \'"\'
];
return str_ireplace( $searchfor, $replaceto, $output );
}
add_filter(\'wp_video_shortcode\', \'EMP_video_shortcode_override\', 10 , 5);