Let’s say you wanted to use the post thumbnail feature of WordPress, but had a whole archive of posts that would take too much time to go through. For new posts, you can be specific and use the feature as intended. For old posts, you just want to use the first image it finds in the content for the thumbnail, or a default if none present.
Add this to functions.php or make a functionality plugin:
I’m not familiar with how to make things work in WordPress – – – but I included similar functionality in my Journal which I recently rewrote (hand coded – not WordPress). It is based on my use of the iFrame Video Embed for HTML5 compatability in my Journal – so won’t work with object and embed code. Hopefully you can use it and adapt it to your WordPress application in a similar way as above with the first image.
This video check code, comes after I have checked to see if there is an image in the content from a post (as I loop through). If it finds an iframe, it uses preg_match to extract the “src” of the iframe – and if there is a match to ‘www.youtube.com’ – I can create a url based on the video id that is extracted from the src url.