WP Gallery Image Shortcode Plugin
Download
The WP Gallery Image Shortcode plugin lets you add an image to a post or page from the WordPress gallery on your site using a shortcode. Simply add the wppgalleryimage shortcode and specify the image you want to add by name, title, or ID.
When you insert an image using the built-in WordPress editor, the full URL to the image on your site is inserted into the page or post. Using the shortcode, all you need to specify is the name or ID of the image and the URL is generated automatically.
When an image is uploaded to the gallery, the file is stored under wp-content/uploads and metadata about the image is stored in the wp_posts table with a post_type of attachment. The image is added to the post or page within a <div> tag that specifies the wpgalleryimage_shortcode class, which allows you to define a style for all images added by the shortcode.
Parameters
- id - The ID of the image in the
wp_poststable. - name - The name of the image from the
post_namefield in thewp_poststable. The name must match exactly. - title - The title of the image from the
post_titlefield in thewp_poststable. The title must match exactly. - size - The size of the image. This value is passed to the
wp_get_attachment_imagefunction.
Valid values include:thumbnail(default)mediumlargefull
- width and height - The width and height of the image to display. The most appropriate image file will be used to display the image. Both must be specified or they will be ignored. If these parameters are specified, the size parameter is ignored.
- float - How to float the image on the page.
Valid values include:none(default)leftright
- link - The URL to link to when the image is clicked on. You can also specify
fullto link to the full-size image. - padding, paddingtop, paddingright, paddingbottom, paddingleft - The amount of padding around the image. If floating left, defaults to
10pxon the right. If floating right, defaults to10pxon the left.
Examples
[wpgalleryimage id=”19″]
[wpgalleryimage name=”my-logo”]
[wpgalleryimage name=”my-logo” size=”medium”]
[wpgalleryimage title=”My Logo” size=”medium”]
[wpgalleryimage name=”my-logo” width=”100″ height=”100″]
[wpgalleryimage name=”my-logo” float=”right”]
[wpgalleryimage name=”my-logo” link=”full”]
[wpgalleryimage name=”my-logo” link=”http://www.example.com/”]
[wpgalleryimage name=”my-logo” paddingbottom=”10px”]
Installation
- Download the wpgalleryimage-shortcode.zip file.
- Unzip the zip file and copy the contents to a folder below
/wp-content/plugins. - Activate the plugin through the ‘Plugins’ menu in WordPress.
- Place the [wpgalleryimage] shortcode in your posts and pages.
Changelog
1.1
- Added support for specifying the image by title.
- Fixed the attachment query to be more reliable.
1.0
- Initial release.




November 24th, 2009 at 1:08 pm
Great idea! I can change picture title in media library and changes are automatically applied to post. But there are many important things missing for better usability. When I find picture in my library then I only want to click on button “Insert as shortcode” and shortcode will be added to post in right format (based on selection in library, for example link to image, align - center and thumbnail). There would be also helpfull to insert shortcode to TinyMCE editor, but see small preview of this image (with notice that it is shortcode).
November 25th, 2009 at 8:57 am
Yep, that’s a good idea. I’ve been thinking about that (integrating into TinyMCE) but hadn’t spent the time to figure out how to do that.
November 30th, 2009 at 10:06 pm
This really helped me out with what I’m working on now. I’m making a wordpress site for a client that wants to control their own content, and most of the content has a logo or an image that is used as a link in a gallery off to the side. The images don’t actually get used in the posts themselves, so they aren’t technically attachments of the posts, so I had to resort to using a custom field. But I couldn’t figure out how to get the image using its name, so I had to put the image ID in the custom field. Well THAT sucked because I realized that the ID is different between my various testing environments and the live site because it’s auto-generated when the file is uploaded (duuuuuh). So the image ID that gets imported with my posts were useless. Your plugin is perfect because I can instruct my client to make sure the image titles match the post titles that they reference, then I have an extra loop that just has this code and everything is good:
$coacheshtml .= ‘<a>ID).’” rel=”bookmark”>’.shortcode_wpgalleryimage(array(”title” => $post->post_title)).’</a>’;
Booyah. No more custom fields. I didn’t use the shortcode per-say, but thanks.
November 30th, 2009 at 10:28 pm
That’s awesome! Thanks for sharing.
March 10th, 2010 at 10:38 pm
Is there a way to use this plugin for a gallery and not a specific image?
I have added a gallery to each post via wp’s built in gallery. I wanted to attach each image in the gallery to the original file in order to allow people to print the full size image but each time I print I get an image on half of the page (the images are landcape and the printer automatically prints on portrait).
I thought I could use your plugin in order to use the link=”full” function. Is there any way that this could be done or do you have an idea how I can solve my problem?
Any help will be much appreciated. The site is: http://www.rewardchartsforchildren.co.uk/