0

What can be an efficient way to determine videos that may be embedded in a post?

If the embed code is directly added to a post, it is easy to determine using regular expressions but some plugins embed videos through shortcodes or in custom fields. In these cases, the actual embed code is added at the time of rendering the post.

2
  • Are you looking to find all the videos in a post no matter how they are included? What specific plugins are you talking about?
    – hornj
    Dec 30, 2013 at 20:10
  • Let's say I am only looking for YouTube URLs in a post. Dec 30, 2013 at 21:26

1 Answer 1

0

This is the statement I am currently using to extract YouTube URLs from a post:

preg_match('|http://www.youtube.com/watch\?v=([a-zA-Z0-9\-\_]+)|', $post->post_content, $matches);

$matches[1] contains the ID of the first video. This may not cover all the YouTube URL formats, but it should give you a start.

2
  • This works only when the YouTube URL is included in the blog posts. Some plugin insert videos through short codes, custom fields and am looking to extract such URLs that aren't int he body. Jan 1, 2014 at 11:15
  • Right, I thought that is what you wanted. But do you know exactly what methods you are using?
    – hornj
    Jan 1, 2014 at 13:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.