WordPress.org

Ready to get started?Download WordPress

Forums

Stripping Youtube Code (23 posts)

  1. nickaster
    Member
    Posted 3 years ago #

    Howdy... it seems that wordpress sometimes strips video embed and iframe code from posts while I'm composing them. It doesn't happen all the time... I think it only happens if I "preview" then come back to edit. It may be related to the author's level of privileges since I haven't seen it when logged in as admin. Is this a known bug?

  2. Curtiss Grymala
    Member
    Posted 3 years ago #

    This is not a bug, it's actually a feature. The visual editor is configured to strip javascript, embed code, invalid HTML, etc. It is slightly less strict for admins (or any users with the unfiltered_html capability) than for authors.

    However, ideally, you should use the oEmbed interface to embed YouTube videos instead of using YouTube's crummy embed code. To use oEmbed, you simply need to make sure the Settings -> Media -> Auto-Embed option is checked in your administration area, then simply insert the URL of the YouTube video.

  3. nickaster
    Member
    Posted 3 years ago #

    Interesting.... it seems to happen even if I'm using the HTML mode, however. I'll try that auto embed thing.

    Wow... it actually works. I'm impressed! Thanks!

  4. If I may chime in here - Curtiss, do you or does anyone know if there's a way to get oEmbed to use YouTube's (and other video sites') iframe embed code, instead of the object/embed Flash method, which won't be viewable on iPads/iPhones? I've been looking for the best way to do this and tried a few iframe plug-ins today, with not great results. Thanks for any suggestions.

  5. Just discovered a thread with some iframe shortcode solutions that look promising:

    http://wordpress.org/support/topic/new-youtube-embed-code-disappearing?replies=7

  6. Curtiss Grymala
    Member
    Posted 3 years ago #

    I was under the impression that the default implementation of YouTube's oEmbed code uses the iFrame now, instead of the embed code. Is it not doing so on your website?

  7. Curtiss - correct, I tried the oEmbed method with a YouTube link and it did not use iframe code, it used the object/embed code. v. 3.0.5.

  8. Curtiss Grymala
    Member
    Posted 3 years ago #

    I just checked online, and it looks like YouTube has not yet made that the default standard.

    However, you can retrieve iFrame oEmbed code by appending &iframe=1 to the end of the oEmbed URL.

    In order to do that, you probably need to hook into whatever WordPress filter is available when the URI is built, but I'm not sure exactly which filter that is right now. I found the oembed_dataparse filter, but that is run after the oEmbed request has already been made, so we'd have to find a filter that runs before that.

    If I get a chance, and noone else answers the question, I'll try to take a look at the source code later to see if I can find the right filter.

  9. Thanks so much, Curtiss! I just tested oEmbed again, adding the &iframe=1 query string and it still used the object/embed code, so you're right - looks like something extra needs to be added. Will be very interested to see if this is possible.

  10. Curtiss Grymala
    Member
    Posted 3 years ago #

    I looked through the source code and couldn't really find any good filters to hook onto, unfortunately.

    However, I did find two plugins in the repository that look like they might be helpful. I haven't used or tested either of them, but they both look promising.

  11. Thanks so much for having a look, Curtiss, I really appreciate it.

    I have tried some YouTube-specific plug-ins and some of them work OK, but I'm hoping to find a solution that will work across all platforms - i.e. to allow Vimeo's iframes, etc. I was planning on testing this one on Monday:

    TSL iframe unfilter

  12. Curtiss Grymala
    Member
    Posted 3 years ago #

    Sorry I couldn't help more.

    FYI, though, the Vimeo oEmbed feature does use iFrame as default, so you don't need any changes at all to use iFrames with Vimeo.

  13. the Vimeo oEmbed feature does use iFrame as default, so you don't need any changes at all to use iFrames with Vimeo.

    Great to know - thanks so much!

  14. nickaster
    Member
    Posted 3 years ago #

    Hey... so I just had a Vimeo video disappear when I edited a post. How am I supposed to embed it? Is there a URL method?

    In all honest, this is still a bit of a bug. What if I wanted to put a normal iframe into a post? Just for the hell of it? WP shouldn't be stripping this stuff!

  15. Ashfame
    Member
    Posted 3 years ago #

    Hi Nick,

    You can use it like this '[embed width="650"]http://vimeo.com/20797313[/embed]'

    Semantically putting iframe in a post is not correct so it is like that with WordPress but with shortcodes, one can do anything they want within the post.

  16. nickaster
    Member
    Posted 3 years ago #

    Okay... this is still a bit of a problem because many people will continue to try and use embed codes, or iframes, and then freak out when they disappear. It's kinda cool that just throwing a URL in there works, but educating people over and over about it gets incredibly tedious.

    Plus, by taking away my power as a publisher to control this stuff, all kinds of annoying problems happen. For example, what if I want to adjust the size of the video? Or center it? With real code I could do that.

  17. Ashfame
    Member
    Posted 3 years ago #

    Well there is the cause why we need to have "Awareness programmes" for so many things in this world ;)

  18. nickaster
    Member
    Posted 3 years ago #

    Yeah, well that's going to do nothing. Not to mention the fact that older post that have embed code could get destroyed too. I just went back to a post a couple months old and the video is gone now. *%#*)%#)%*)#*%)#*%#

    This is totally unacceptable and WP should have an option to allow the embed. I don't care if it's incorrect code, it works and this is totally screwing people with older posts and lots of writers.

  19. nickaster
    Member
    Posted 3 years ago #

    Dare I ask .... does anyone know how to size the video if I wanted to? Just slapping in the URL seem to automatically will the whole post width. What if I wanted it smaller?

  20. Pat Hawks
    Member
    Posted 3 years ago #

    To change the size, just wrap the URL in the [embed] shortcode and give it a height and width attribute.
    Alternatively, you can change the size for all embeded videos in the ** Settings -> Media ** page in the dashboard.

    For YouTube embeds using the iframe embed code, you can use the plugin Better YouTube Embeds. It simply tells WordPress to use YouTube's iframe oembed endpoint instead of the Flash oembed endpoint.
    This means, you won't have to use any new shortcodes or special syntax. All YouTube videos embeded using the standard embed syntax will get the new iframe player.

  21. nickaster
    Member
    Posted 3 years ago #

    Interesting... that helps, thanks!

    Still, the problem with all this is that inexperienced authors are NEVER going to understand it and it leaves me, the editor, having to constantly fix people's code. It's hard enough getting people to understand just pasting whatever youtube spits out.... sigh

  22. Pat Hawks
    Member
    Posted 3 years ago #

    No argument there, things could certainly be easier for novice users.

    If you have any ideas, I'd be willing to work with you on a plugin.

  23. nickaster
    Member
    Posted 3 years ago #

    Seriously, F*** this. Why can't there at least be some kind of legacy here??? I get dozens of guest posters a week and inevitably some guy emails me wondering why his video is not in the post. Yeah, they should know better, but you know that's never going to happen. When I try to edit these posts it still takes me forever to even figure out how to format the ***ing YouTube URL... this is not straightforward, and should never be called a feature. I know I'm not the only one!

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.