A feature requested multiple times for Automatic Featured Image Posts is the ability to insert the new image into post content in addition to assigning it as the featured image for the post.
I tried a few things to make this work, but there are two primary issues:
- I hook into the ‘add_attachment’ hook in WordPress. This runs immediately after an image is uploaded and the attachment data is added to the database. I can grab this data immediately, but only for the full size version of the new image. The thumbnails are crunched in the background and I haven’t yet found the right way to grab a smaller image for display. This works fine at times, but your site could quickly become bogged down with multiple 2MB files loading on your home page.
- If I was able to solve the first issue, it would still be hard to determine what the new post content should look like. Should I only use the medium image? Should it be center aligned? The varieties are fairly endless, where as using the featured image makes the display very flexible. [what are WordPress Post Thumbnails/Featured Images?]
So with those in mind, while this request stretches the bounds of the primary purpose for the plugin, it is easy enough to provide filters to allow content to be handled on a custom basis.
With today’s update for Automatic Featured Image Posts, I’m adding 3 filters that allow you to easily set the new post title, categories, and content as you upload images. The new image will continue to be attached as the featured image for the post, but this will allow more flexibility for those who want it.
Here are a few snippets that show the filters in action. These can be added to your theme’s functions.php file, or, as is often applicable, to the child theme you have created from your primary theme of choice.