1

I was using the code below to set the default size for embeded objects in my posts. It worked before for me but now it no longer works.

 add_filter( 'embed_defaults', 'bigger_embed_size' );

 function bigger_embed_size()
 { 
 return array( 'width' => 935, 'height' => 525 );
 }

I also used this css so that when viewed from mobile devices the width of the embeded object would be so tall.

embed,
iframe,
object,
script,
video {
margin-bottom: 1.6em;
max-width: 100% !important;
vertical-align: middle !important;
min-height:250px;
}

None of these options are working anymore does anyone have a solution.

  • Have you added any plugins that might override them? Perhaps upping the priority might help. add_filter( 'embed_defaults', 'bigger_embed_size', 100 ); – Ben Casey Mar 14 '17 at 8:24
  • I don't think i've added any plugin that would effect media sizes – Terrell Anderson Mar 14 '17 at 8:26
  • and upping the priority didn't help :( – Terrell Anderson Mar 14 '17 at 8:27
  • silly question, but sometimes its those that answer the problem, is the add_filter actually running? try die('HERE') right before it and ensure that "HERE" is the only thing printed to the screen. Otherwise try looking for PHP errors. – Ben Casey Mar 14 '17 at 8:29
  • is it public so we can see the issue? – Ben Casey Mar 14 '17 at 8:29
0

This is what I crafted to override the defaults, I set a default media width, choose an aspect ratio (16:9) and then replace the video shortcode output.

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.