WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] How to set max width of oembeds in WP 3.5? (14 posts)

  1. rossagrant
    Member
    Posted 1 year ago #

    Oembed settings for max height/ width etc used to be under the settings--->media tab.

    This now only seems to reference images and not video embeds etc.

    Anyone know where this can be set?

    It's super important as otherwise oembeds just spill over the body of the theme.

    Please can someone let me know!

    Thanks :)

  2. archon810
    Member
    Posted 1 year ago #

    Same issue after upgrading to 3.5. Release notes say it should default to content width, but it's not so for androidpolice.com. I upgraded a test install, and embeds are left aligned and occupy about 2/3 of the post width.

    Gotta love removing all related settings, as per notes, but not specifying a way to tweak it if it doesn't work right. Time to go dig through the code.

  3. rossagrant
    Member
    Posted 1 year ago #

    I'm using Buddypress and the youtube oembeds just appear huge and spill right over the body of the activity stream pages and forums.

    Funnily enough, existing oembeds are fine, they seem to retain the max width set in the previous version.

    This seems to be a pretty big oversight that needs fixing fast IMO.

    Let me know how you get on.

  4. archon810
    Member
    Posted 1 year ago #

    @rossagrant Existing oembeds are cached in WordPress and will therefore use the cached embed tags. If you clear out the cached values, they'll get re-requested and will then grow out of control as per current settings.

  5. rossagrant
    Member
    Posted 1 year ago #

    Ahh okay, well this needs fixing ASAP then!

    Can't believe they took away this functionality!

  6. Samuel Wood (Otto)
    Tech Ninja
    Posted 1 year ago #

    What is the content_width set to by your theme? If there is no global $content_width set by the theme (or anything else, really), then it defaults to 500 pixels wide.

  7. Samuel Wood (Otto)
    Tech Ninja
    Posted 1 year ago #

    Note that this is easy to change, and any modern theme should have it set properly for that theme already.

    In the theme's functions.php, there should be something like this:

    global $content_width;
    $content_width = 500;

    Or whatever the width of the main content area is.

  8. archon810
    Member
    Posted 1 year ago #

    That did it, Otto.

    I am willing to bet that many people don't have an up-to-date theme or a theme was created in-house without this option (first time I've heard of it myself for example).

    Either way, thanks for the help.

  9. Samuel Wood (Otto)
    Tech Ninja
    Posted 1 year ago #

    Note that the content width affects *loads* of things, so it is important that you set it to the actual width of the "content area" of your theme, not just to how wide you want oembeds to be. Content width also determines the maximum size of embedded images, for example.

    Also, our Theme Check plugin will warn you about issues like this with themes. We use this here on WordPress.org for helping theme authors clean up their themes before submitting to the theme repository. Might be worth giving it a run over your theme too. :)

  10. rossagrant
    Member
    Posted 1 year ago #

    So what if I don't want oembeds the full width Sam?

    Is there any specific function just for the oembeds?

    Not quite sure why the old settings had to go. They were great and super flexible for everyone?

  11. Samuel Wood (Otto)
    Tech Ninja
    Posted 1 year ago #

    Almost nobody used them, actually, and there wasn't a good reason to have them. They defaulted to the content width, and adjusting them individually like that didn't make a lot of sense.

    Furthermore, it was argued that this should really be a function of the theme. Users generally want things to look right to start out with, not to micromanage the layout. The theme should define the widths and things.

    If you absolutely, positively, must custom set this value to something else, here's some code you can put in the theme's functions.php file.

    add_filter('embed_defaults','themename_embed_defaults');
    function themename_embed_defaults($defaults) {
       $defaults['width']=123;
       $defaults['height']=123;
       return $defaults;
    }

    This is what themes should use if they need to set special case default sizes for oembed'd content. Note that both width and height are considered "max" sizes, the actual content returned from the provider will be whatever the provider wants to return. No guarantees on exact sizing.

  12. rossagrant
    Member
    Posted 1 year ago #

    Cheers Otto,

    I'm just not sure exactly how my theme works, it's a new kind of framework that is still kind of in beta, so if I can manage this stuff manually for now then that might be best.

    I'll try that function, thanks for your help!

  13. helloari
    Member
    Posted 1 year ago #

    this thread was very helpful. i had what i thought was a great theme by graphpaperpress but i guess it overlooked this detail.

    this is an issue - kinda breaks the backward compatibility of wordpress in a small way.

    the fix was easy however.

  14. 360zen
    Member
    Posted 1 year ago #

    This was exactly what I needed. Thanks!

Topic Closed

This topic has been closed to new replies.

About this Topic