King Mo's Blog

Coding 'n shit

My “Auto Image Adder” – WordPress Plugin

Edit:

I haven’t developed this any further yet and am currently not really planning on doing so. If you still are interested in this or have any bugs which you really really need to have fixed you still can contact me for sure and we’ll see what I can do :) Just wanted to drop this little warning here, I don’t really know if this is still working or not, maybe I’ll come back to this some day 😉

Description

This Plugin can automatically add Pictures to your posts when publishing. For this it does a Google image search for the Post title and scrapes the first Image. You can choose if the image should be saved in your WordPress or just linked to the original source. Further you can change if the image should be added to the post itself, if so you can choose the alignment, or if it should be set as the Posts featured image or both.

Below is a guide on how to set it up, the download link can be found at the bottom.

How to use it

Installation

In the ZIP-file there is a folder named “auto-image-adder”. Just add this folder to your Plugin directory and then activate it in the WordPress Dashboard. That’s it.

Configuration

All settings can be found under “Settings” -> “Writing”.

  • Save image or just link it – If set to “Save”, the picture will be saved in your own WordPress. If set to “Link”, the picture, when added to the post, will just be an <img>-tag with it’s src-attribute set to the original source.
  • Set image as featured image – If this option is selected the image will be set as the Posts featured image. Also the first option will be ignored because the image has to be saved in WordPress to be set as featured image anyways.
  • Add image to the post – If this is set, the image will be prepended to the Posts content when publishing.
  • Image class(es) – When an image is added to the post, here you can define which class(es) it should be given.
  • Image size – This is used for the scraping. These are the same values as in Google’s image search. Therefor this isn’t do “crop” the images but to initially only search for images this size.
  • Image align – If the image is added to the posts content, this decides if it is aligned left, right or in the middle.

Additional feature – Shortcodes

Another feature built into this plugin is the possible usage of shortcodes. You can use the shortcode [google-search-img] to add scraped images to any post.

Parameters

  • q=”[search query]”
  • align=”left|center|right”
  • size=”large|medium|pictogram|lt400x300|lt640x480|lt800x600|lt1024x768|lt1600x1200|lt2272x1704″
  • offset=[offset-number]
  • link=”[URL]”
  • class=”[class(es)]”
  • id=”[id]”
  • a-class=”[link class(es)]”
  • a-id=”[link id]”

with q you can set another query used to search an image.

offset is the 0 based value of which image from google to take. So 0 is the first, 1 is the second, 2 is the third and so on.

Example

Let’s say you want to add the first 3 results for a search for “ice cream cone” and you want them centered and “large” then you would add the following to your post content:

[google-search-img q="ice cream cone" align="center" size="large" offset=0]
[google-search-img q="ice cream cone" align="center" size="large" offset=1]
[google-search-img q="ice cream cone" align="center" size="large" offset=2]

Note

Be aware that with the shortcodes (yet) there is no way to save the scraped images. Might build in this option soon but by now it scrapes the images every time the post is loaded. Therefor too extensive use of this feature may slow down the loading time of the page. Also it is not given that these images are always the same because the order of results in the image search may change.

I hope you’ll like it

There is quite some effort put into this Plugin so hopefully somebody may find it useful. If you have any suggestions on how to improve this Plugin or just appriciate it I would be happy if you leave me a comment. Also if there are any bugs please let me know so I can fix it as soon as possible!

Here’s the link

http://blog.king-mo.solutions/wp-content/uploads/2015/04/auto-image-adder.zip

Previous

Blueprint for a secure and cloaked content locking solution

Next

My Magento Modules

1 Comment

  1. Very nice plugin, i have to pay for articles I don’t write, and i don’t want to sit around and look for pics. This plugin makes my day more easier and my blog looks alot nicer.

Leave a Reply

Powered by WordPress & Theme by Anders Norén