You can do this. Don't have them enter the embed code though. Just have them enter the YouTube URL. Then in your Content Template for the post body, insert the custom field where they entered the YouTube URL (before or after the other form fields they submitted, however you want it laid out.)
In your admin, under Options > Media (http://example.com/wp-admin/options-media.php) there is a section (mid-way down) called "Embeds":
Auto-embeds: When possible, embed the media content from a URL directly onto the page. For example: links to Flickr and YouTube. When possible, embed the media content from a URL directly onto the page. For example: links to Flickr and YouTube.
Make sure you check that. In WordPress since 2.9, they use oEmbed to "auto-embed" YouTube and Flickr and all sorts of things - all you need to insert is the URL. You can read more about it here.
Simple, sample form:
http://guitar.chrishajer.com/2011/07/11/submit-a-youtube-video-to-our-contest/
Enter a YouTube URL there and it should work fine. I have the post set to publish automatically. You'll have to go to the home page of the site to see your post.
For my post body, I have only this:
[embed]{YouTube:7}[/embed]
The embed shortcode is optional, but it lets you do other things (like specify width and height if you want to.) I tried without wrapping my custom field in the shortcode, in the content template, and it worked that way on my site as well. To be safe, the embed shortcode cannot hurt you.
So, yes you can do this, without a doubt. You might want to do some sort of validation on the YouTube URL and have the posts made as drafts, but as you can see in this simple example, it works fine.
Posted 13 years ago on Tuesday July 12, 2011 |
Permalink