Support » Fixing WordPress » oEmbed now only has the width of 500px

  • Resolved azn137

    (@azn137)


    After upgrading my WordPress to 3.5, all of my embedded videos are showing up with the width of 500px. How do I change it?

    There’s no longer embed default size in Settings >> Media Settings.

Viewing 6 replies - 1 through 6 (of 6 total)
  • For the time being, with WordPress 3.5, I’ve modified the function in /wp-includes/media.php to have the width of what I want:

    function wp_embed_defaults() {
    	if ( ! empty( $GLOBALS['content_width'] ) )
    		$width = (int) $GLOBALS['content_width'];
    
    	if ( empty( $width ) )
    		$width = 613;
    
    	$height = min( ceil( $width * 1.5 ), 1000 );
    
    	return apply_filters( 'embed_defaults', compact( 'width', 'height' ) );
    }
    Drew Jaynes

    (@drewapicture)

    Docs Czar

    Hi azn137,

    Best practice is to never hack core!

    The Embed size options were intentionally removed in 3.5. By default, if no content_width is defined, WordPress defaults to 500px. Maximum height is automatically calculated at 1 1/2 times the width.

    However, just because your theme hasn’t set a content_width, it doesn’t mean you can’t.

    You can put something like this in your theme’s functions.php file to change the default, where 500 represents the width in pixels:

    function my_content_width() {
    	global $content_width;
    	$content_width = 500;
    }
    add_action( 'template_redirect', 'my_content_width' );

    Drew, IMO that’s gonna cause a lot of issues, since some, if not most, themes don’t already have the variable set.

    Thanks for the code by the way. I guess I’d rather modify my theme file than core file.

    Drew Jaynes

    (@drewapicture)

    Docs Czar

    Drew, IMO that’s gonna cause a lot of issues, since some, if not most, themes don’t already have the variable set.

    Right. The point is to get theme authors to set a content_width in their themes.

    Also, I notice that the core function you hacked actually has a filter on the end of it. Filters are made for modifying output of core functions.

    Instead of the function above, you could just filter the core function directly with something like this:

    function filter_embed_sizes() {
    	return array( 'width' => 500, 'height' => 1000 );
    }
    add_filter( 'embed_defaults', 'filter_embed_sizes' );

    Thanks!

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘oEmbed now only has the width of 500px’ is closed to new replies.