[Resolved] Change video embed size

Home Forums Support [Resolved] Change video embed size

Home Forums Support Change video embed size

Viewing 12 posts - 1 through 12 (of 12 total)
  • Author
    Posts
  • #224775
    Doug

    Hello,

    I’m trying to change the default width of videos I post from YouTube, Vimeo, etc, so that simply pasting the video URL in the visual editor will embed the video at the proper dimensions.

    I read through this forum page, and tried a few things:
    https://generatepress.com/forums/topic/wrong-video-size/

    a. I tried changing the global $content_width value, but that didn’t make any visible change
    b. I downloaded the responsive video embeds plugin, which works really well, but it requires an extra step in the posting process, and I’m trying to reduce steps wherever possible for the sake of the people I’ve set up the website for.
    c. Manually embedding is slower than the plugin, so nevermind that option.

    Thanks for a fantastic theme by the way, it’s been a lifesaver for my current project.

    Best,
    Doug

    #224839
    Tom
    Lead Developer
    Lead Developer

    $content_width is most likely what you’re looking for, you might just have to hook it in a little later:

    add_action( 'wp', 'tu_custom_content_width', 20 );
    function tu_custom_content_width()
    {
        global $content_width;
        $content_width = 500;
    }

    Adjust the width as needed πŸ™‚

    #225072
    Doug

    Thanks for the quick reply Tom, really appreciate it.

    Sorry–where exactly in my functions.php should this go? Is this replacing any code?

    #225074
    Lyle

    Hi Doug,

    Not sure if you are aware of this, or if it relates to your question, but perhaps have a read through this YT post on how to select a different embed size when getting the embed code:

    https://youtube.googleblog.com/2010/03/new-default-size-for-embedded-videos.html

    Basically, when you click the Embed item on Share, you get the default iframe embed code highlighted, ready to copy. Click the Show More link and then you can choose the Video size from that drop down selector (default is 560 x 315).

    Cheers!
    Lyle

    #225108
    Tom
    Lead Developer
    Lead Developer
    #225305
    Doug

    Thanks Tom,

    I haven’t gotten around to adding this code yet, but will eventually just to try it out. Turns out the people I’m making this for are okay using the plugin, but this article will come in handy in the future.

    Thanks a lot for the help!
    Doug

    #225306
    Doug

    I wasn’t aware of that before, that’s a real useful too, thanks Lyle!

    #225345
    Tom
    Lead Developer
    Lead Developer

    No problem Doug πŸ™‚

    #244987
    Jessica

    Somthing funky is going on with the responsiveness of videos. I have 2 nearly identical sites (I just changed the content and typography) but the CSS & function are exactly the same… the YouTube video is pasted into the page/post exactly the same, but on one site, the video isn’t responding.

    the css is:

    .video-container {
        position: relative;
        padding-bottom: 56.25%;
        padding-top: 30px; height: 0; overflow: hidden;
    	}
     
    	.video-container iframe,
    	.video-container object,
    	.video-container embed {
    	    position: absolute;
    	    top: 0;
    	    left: 0;
    	    width: 100%;
    	    height: 100%;
    	}

    the function code is:

    add_filter( 'embed_oembed_html', 'custom_oembed_filter', 10, 4 ) ;
    function custom_oembed_filter($html, $url, $attr, $post_ID) {
        $return = '<div class="video-container">'.$html.'</div>';
        return $return;
    }

    On the first (original site) the video link is simply pasted in with NO wrapper added. And the site identifies it as a video, and works great.

    the second site, all using exact same methods, code, css, etc… the videos aren’t responding.

    I am not going to be able to put an html wrapper around every video b/c there will be so many it will totally defeat the purpose of the action & css I used.

    I’m baffled. The only difference between these 2 sites are the urls. Everything else is the same methodology. Help!?

    #245026
    Tom
    Lead Developer
    Lead Developer

    It could be a plugin you’re using on the second site which is interfering with the filter you’ve added for the embed.

    Worth deactivating them one by one just to check.

    #245269
    Jessica

    Actually…confession? I am a moron.
    As we all are very familiar, code is extremely sensitive. And there was literally one word I forgot to change in my functions file that I finally found, corrected, and of course now everything is working fine. So that happened.

    Thanks for responding. Hopefully one day before the end of the year I’ll be able to show you the sites that I’ve been creating πŸ˜‰

    #245318
    Tom
    Lead Developer
    Lead Developer

    Looking forward to it! πŸ™‚

Viewing 12 posts - 1 through 12 (of 12 total)
  • You must be logged in to reply to this topic.