最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

php - How to overwrite youtube embed?

matteradmin9PV0评论

I really like how you can just paste a URL right into the post... such as:

or

What I want to do is change the default code for this to support the code from here: /

How can I go about overwriting the youtube and vimeo code, I'm assuming in functions.php somehow?

I really like how you can just paste a URL right into the post... such as:

http://youtube/watch?v=xyz or http://vimeo/123456

What I want to do is change the default code for this to support the code from here: http://embedresponsively/

How can I go about overwriting the youtube and vimeo code, I'm assuming in functions.php somehow?

Share Improve this question edited Feb 11, 2014 at 20:08 Tallboy asked Feb 11, 2014 at 19:07 TallboyTallboy 2278 silver badges17 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 2

Taking a closer look at the code provided on that site, it appears that the main differences with what it output by default by WordPress is the following:

  • the iframe is wrapped with a div that has a class of embed-container
  • there are CSS styles that are used by that class

In WordPress, to wrap the embed iframe, add the following to your theme's functions.php or to a functionality plugin:

add_filter('embed_oembed_html', 'my_embed_oembed_html', 99, 4);
function my_embed_oembed_html($html, $url, $attr, $post_id) {
return '<div class="embed-container">' . $html . '</div>';
}

and add the CSS generated by http://embedresponsively/ to your theme:

.embed-container { 
position: relative; 
padding-bottom: 56.25%; 
padding-top: 30px; 
height: 0; 
overflow: hidden; 
max-width: 100%; 
height: auto;
} 

.embed-container iframe, .embed-container object, .embed-container embed { 
position: absolute; 
top: 0; 
left: 0; 
width: 100%; 
height: 100%;
}

I tested the filter and it worked just fine. I did not test the CSS though, that will be up to you to play with.

Source for the filter: http://wordpress/support/topic/adding-a-wrapping-div-to-video-embeds?replies=2

Articles related to this article

Post a comment

comment list (0)

  1. No comments so far