- This topic has 11 replies, 4 voices, and was last updated 7 years, 4 months ago by Tom.
-
AuthorPosts
-
September 7, 2016 at 2:08 pm #224775Doug
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,
DougSeptember 7, 2016 at 10:55 pm #224839TomLead DeveloperLead 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 π
September 8, 2016 at 6:14 pm #225072DougThanks for the quick reply Tom, really appreciate it.
Sorry–where exactly in my functions.php should this go? Is this replacing any code?
September 8, 2016 at 6:34 pm #225074LyleHi 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!
LyleSeptember 8, 2016 at 9:49 pm #225108TomLead DeveloperLead DeveloperThis should help for adding PHP: https://generatepress.com/knowledgebase/adding-php-functions/
September 9, 2016 at 12:36 pm #225305DougThanks 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!
DougSeptember 9, 2016 at 12:42 pm #225306DougI wasn’t aware of that before, that’s a real useful too, thanks Lyle!
September 9, 2016 at 8:41 pm #225345TomLead DeveloperLead DeveloperNo problem Doug π
November 16, 2016 at 5:16 pm #244987JessicaSomthing 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!?
November 16, 2016 at 8:38 pm #245026TomLead DeveloperLead DeveloperIt 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.
November 17, 2016 at 10:59 am #245269JessicaActually…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 π
November 17, 2016 at 12:58 pm #245318TomLead DeveloperLead DeveloperLooking forward to it! π
-
AuthorPosts
- You must be logged in to reply to this topic.