Using the WordPress Media library to store images to be used in multiple posts.

One of my new years resolutions is to start sharing more WordPress code tips here, so here’s one!

I’m working on a “Customer Portal” for a landscaper client.  One of the features is using the wordpress Media Library to store photos of various plants, including care information which would be stored in the Description field of the image.

This way, a collection of plants could be displayed in a single post for the customers review, and she can use the plants over an over again in different communications with customers.

There were a couple of things I had to do to make this workable for her, and I thought sharing here would help others!

For one thing, reusing the images multiple times means you can’t easily use the built in WordPress Gallery functionality, since the images are NOT attached to the posts (they are just Inserted it them).

We also wanted to display the description in the image caption.

Finally, this needed to be very easy for the client to do, and fast.

Improve Usability of the Image Insert functionality in WordPress

Since we are using images that may or may not be attached to the posts (some may be uploaded at the time the post is created, but others will be pulled from the media library) we can’t easily use the Gallery function.*  So for each image you have to insert the image you want, then open the dialog up again to insert the next one, and so forth.

Also, I find that if there is one thing that will screw up the formatting of a wordpress post it’s using the Caption in the Visual Editor, so I generally steer non-techie clients away from it.

But in this case, we did want to use the Caption, and I foresaw support calls in my future if we didn’t make it super easy for the client.

Solution: Faster Image Insert plugin

This plugin adds checkboxes next to the images on the the Upload/Insert image dialog.  So to insert multiple images at a time from the Media Library, just confirm the settings (size, caption, etc) for each of the photos, click the checkboxes of the ones you want inserted, and insert them all at once!

So much easier than inserting them all individually, and less prone to errors because the user clicked in the wrong place and inserted his next image into a caption!

*If you wanted to use the Gallery functionality, you would have to specify the # of the attachment each time using the gallery include = syntax, but that was ruled out as too complicated for the user.  We needed a way to let her just choose the images she wanted and insert them.

How to add the description to the image caption (WordPress)

The next problem to solve was showing the description in the caption area.  She didn’t want the user to have to click on the image to get to the Attachment page to see the image description.

This one I found by a little Googling, and it works like a charm.  Thanks Web Citizen Mag!

Recently for a project, we needed to utilize the description field to dump in additional photo information, while the caption field was used to provide the regular text caption.

To get WordPress to display the description inside the post we had to override the the default image shortcode function WordPress used to generate the final HTML output for the images inside posts.  Then we needed to make some changes to our stylesheet and we were set.

Go there to read the how-to!

Basically go to the link above and copy the code provided to your functions.php file.  The example provided is excellent.

The only change I made to the code was that I wanted to show the description under the caption, instead of on top, so I made the following change to the return:

So now I just added some formatting to the css for the Description info, and we are good to go!

Easy peasy.

Final Product – Media Library (non-attached) Images displaying Descriptions within a WordPress post!