Good afternoon all,
I have recently installed a new theme on my WordPress blog to get with the times as this new theme works really well on mobile whereas my current theme doesn’t.
What I like about this new theme is that uses thumbnails for the blog posts by linking to the "Featured Image" inside the blog post admin panel.
This is great, however, all of my 10,000+ articles do not have a Featured Image assigned to them as my previous theme did not use it.
I have an image that I link to at the top of my articles, which is what I use for the thumbnails when the article is shared to social media etc. These images are uploaded to a different part of my website and I link to them, so they are not stored in the WordPress Media Library.
My question now is: Is there a way that I can make it so my WordPress blog automatically uses the "first image in content" for the "Featured Image"?
I don’t think there are any plugins to do this, so I believe it is some code that I may need to change in the backend of my blog?
I look forward to a response.
Thank you.
2
Answers
This plugin looks like it may suit your need well: https://wordpress.org/plugins/quick-featured-images/.
The images not being in the Media Library might actually make this easier: a combination of a regular expression to identify the URL of the first image in the post, plus
download_url()
,wp_handle_sideload()
, andwp_insert_attachment()
will complete this.You could bypass the use of
download_url()
by providing the current image path towp_handle_sideload()
; that’s up to you.The regular expression would look something like this:
Source: https://wordpress.stackexchange.com/a/60267/59678
Similar question’s answer with example:
https://wordpress.stackexchange.com/a/251512/59678