Filters In Automatic Featured Image Posts

7

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:

  1. 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.
  2. 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.

Automatic Featured Image Posts can be downloaded through the WordPress repository. More info can be found through the overall project status page.

7 comments

  1. Alex says:

    Hi!
    I really love your plugin, because I’m a photoblogger and I like to share my pics online.
    I would like to know if it is possible to fill the content of the article with the exif data of di pics and use the exif title as title of the article.
    I’ve seen there is some exif code in the plugin, but I did not understand how to use it.

    Thank you so much for this plugin!
    Alex.

    • Jeremy Felt says:

      Hey Alex,

      This can actually be accomplished through the use of the ‘afip_new_post_content’ filter included with the plugin. It passes the post ID of the new attachment, so you can use that to pull all of the EXIF information that WordPress has already stored for it.

      • Chris says:

        This sounds very useful indeed! I have set this plugin up and it is running fine for me so far. Then I thought if I added EXIF data I could set the Category and Tags automatically! What do I have to do to make the filters work? Sorry if I have misread the above

        • Chris says:

          Ok maybe I misread the above slightly but it would be good if it could look into the image itself and take the data from the file.

          For example:
          Title = Post Title
          Subject = Category
          Tags = Tags
          Comments = Content

          Personally I only need to set the “Category” and add “Tags” to the post via the image automatically.

          Hope we can work something out.

          Cheers
          Chris

  2. spikethelobster says:

    Absolutely awesome plugin for my needs and these extra functions have made my life a ton easier. I have one question, if I may? Is there a simply way to set the final function – to insert the image in the post – so that it always uses the “medium” setting? (I’m rubbish at coding and stuff so just looking for a hardwired change, really.)

  3. kurt says:

    hi,

    i have installed your plugin and it works awesome. thank you very much! i just read the stuff about filters and wanted to ask if someone has already coded a solution for additionally using the tags in the exif data… So i could add the tags in Adobe Bridge and upload the whole stuff…

  4. Mike says:

    A plugin i was looking for years ….

    Thanks Alex For this wonderful plugin .
    Everything is working as mention in your blog.
    I’d like you to help me with a simple issue … I’m sure you can do this easily …
    $post_content = ‘This is my new uploaded image….';

    I’d like to add the title, author and the date ..
    $post_content = ‘This post – $post_title() ; is uploaded by the_author() on the_time() on category the_category() … Hope you enjoyed this ….';

    Can you pls help out with this …

    Many Thanks in Advance!

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>