Title: [Plugin: Multiple Post Thumbnails] Adding direct URL src to plugin with wp_get_attachment_image_src
Last modified: August 20, 2016

---

# [Plugin: Multiple Post Thumbnails] Adding direct URL src to plugin with wp_get_attachment_image_src

 *  Resolved [gabrielstuff](https://wordpress.org/support/users/gabrielstuff/)
 * (@gabrielstuff)
 * [13 years, 8 months ago](https://wordpress.org/support/topic/plugin-multiple-post-thumbnails-adding-direct-url-src-to-plugin-with-wp_get_attachment_image_src-to/)
 * Hi !
 * I needed to be able to just fetch the src of the secondary image in a specific
   size.
    Thus I added that :
 *     ```
       /**
       		 *
       		 * @param string $post_type The post type.
       		 * @param string $id The id used to register the thumbnail.
       		 * @param int $post_id Optional. The post ID. If not set, will attempt to get it.
       		 * @param string $size Optional. Image size.  Defaults to 'thumbnail'.
       		 * @return src of the Thumbnail or false if the post doesn't have a thumbnail for the given post type, and id.
       		 */
       		public static function get_attachment_image_src($post_type, $id, $post_id = 0, $size = 'post-thumbnail') {
       			if (!$post_id) {
       				$post_id = get_the_ID();
       			}
   
       			$post_thumbnail_id = self::get_post_thumbnail_id($post_type, $id, $post_id);
       			$image = wp_get_attachment_image_src($post_thumbnail_id, $size);
       			if(is_array($image))
       				return $image[0];
       			else
       				return false;
       		}
       ```
   
 * I’m happy with it ! Thanks for your work. Please do not hesitate to add this 
   function to your next update.
 * [http://wordpress.org/extend/plugins/multiple-post-thumbnails/](http://wordpress.org/extend/plugins/multiple-post-thumbnails/)

Viewing 11 replies - 1 through 11 (of 11 total)

 *  [lord_dev](https://wordpress.org/support/users/lord_dev/)
 * (@lord_dev)
 * [13 years, 7 months ago](https://wordpress.org/support/topic/plugin-multiple-post-thumbnails-adding-direct-url-src-to-plugin-with-wp_get_attachment_image_src-to/#post-3122719)
 * You sir, are a gentleman and a scholar!
 * Exactly what I was looking for, and may I suggest this is added to the next version?(
   I presume if there is an update, it will just override this code)
 *  Thread Starter [gabrielstuff](https://wordpress.org/support/users/gabrielstuff/)
 * (@gabrielstuff)
 * [13 years, 7 months ago](https://wordpress.org/support/topic/plugin-multiple-post-thumbnails-adding-direct-url-src-to-plugin-with-wp_get_attachment_image_src-to/#post-3122720)
 * Yup ! upadte with modified core plugin file = code go away 🙂
 * Actually the function is public, so we could try to make it update safe by overriding
   the function it self in a `if` statment.
 * I’ll test that later.
 *  [charmedworks](https://wordpress.org/support/users/charmedworks/)
 * (@charmedworks)
 * [13 years, 7 months ago](https://wordpress.org/support/topic/plugin-multiple-post-thumbnails-adding-direct-url-src-to-plugin-with-wp_get_attachment_image_src-to/#post-3122733)
 * Hi, I would like the thumbnail to link to the large version. Can I use the code
   above to facilitate this and how would I do it?
 * The featured image (regular thumbnail) can be referenced this way to link to 
   the large version of the image:
 *     ```
       <?php
        if ( has_post_thumbnail()) {
          $large_image_url = wp_get_attachment_image_src( get_post_thumbnail_id(), 'large');
          echo '<a href="' . $large_image_url[0] . '" title="' . the_title_attribute('echo=0') . '" >';
          the_post_thumbnail('thumbnail');
          echo '</a>';
        }
        ?>
       ```
   
 *  [charmedworks](https://wordpress.org/support/users/charmedworks/)
 * (@charmedworks)
 * [13 years, 7 months ago](https://wordpress.org/support/topic/plugin-multiple-post-thumbnails-adding-direct-url-src-to-plugin-with-wp_get_attachment_image_src-to/#post-3122735)
 * Also posted in the question about a different function get_post_thumbnail_url
   as I thought that might be able to be used to do this, but would prefer the method
   above if possible, not trying to overpost, thank you.
 *  [charmedworks](https://wordpress.org/support/users/charmedworks/)
 * (@charmedworks)
 * [13 years, 7 months ago](https://wordpress.org/support/topic/plugin-multiple-post-thumbnails-adding-direct-url-src-to-plugin-with-wp_get_attachment_image_src-to/#post-3122736)
 * Hi, I found this:
 * [http://wordpress.org/support/topic/plugin-multiple-post-thumbnails-llink-to-full-size-image-from-thumbnail?replies=14](http://wordpress.org/support/topic/plugin-multiple-post-thumbnails-llink-to-full-size-image-from-thumbnail?replies=14)
 * Which I had missed earlier, and used code modified from here to make my link 
   to larger images work. Thanks!
 *  Plugin Author [Chris Scott](https://wordpress.org/support/users/chrisscott/)
 * (@chrisscott)
 * [13 years, 6 months ago](https://wordpress.org/support/topic/plugin-multiple-post-thumbnails-adding-direct-url-src-to-plugin-with-wp_get_attachment_image_src-to/#post-3122752)
 * [@gabrielstuff](https://wordpress.org/support/users/gabrielstuff/) thanks for
   this!
 * Instead of adding a new function, I’ve updated `get_post_thumbnail_url()` so 
   to add size as an optional parameter so the function signature will look like:`
   get_post_thumbnail_url($post_type, $id, $post_id = 0, $size = null)`
 * This will be in version 1.5 which is coming out in the next few days.
 *  [lord_dev](https://wordpress.org/support/users/lord_dev/)
 * (@lord_dev)
 * [13 years, 4 months ago](https://wordpress.org/support/topic/plugin-multiple-post-thumbnails-adding-direct-url-src-to-plugin-with-wp_get_attachment_image_src-to/#post-3122783)
 * Hi Chris Scott,
 * Thanks for your great plugin.
 * Have you updated this function yet: get_post_thumbnail_url($post_type, $id, $
   post_id = 0, $size = null)
 * I have just updated your plugin to the latest version and I cannot get this to
   work just like the original function at the top of this page.
 * Any help appreciated!
 *  Plugin Author [Chris Scott](https://wordpress.org/support/users/chrisscott/)
 * (@chrisscott)
 * [13 years, 4 months ago](https://wordpress.org/support/topic/plugin-multiple-post-thumbnails-adding-direct-url-src-to-plugin-with-wp_get_attachment_image_src-to/#post-3122785)
 * Can you test this out with the following: [https://raw.github.com/voceconnect/multi-post-thumbnails/master/multi-post-thumbnails.php](https://raw.github.com/voceconnect/multi-post-thumbnails/master/multi-post-thumbnails.php)
 * Adds an optional $size parameter to `get_post_thumbnail_url` to pass in the thumbnail
   size.
 *  [lord_dev](https://wordpress.org/support/users/lord_dev/)
 * (@lord_dev)
 * [13 years, 3 months ago](https://wordpress.org/support/topic/plugin-multiple-post-thumbnails-adding-direct-url-src-to-plugin-with-wp_get_attachment_image_src-to/#post-3122787)
 * Chris Scott – Works perfectly thanks!!
 * When will you release the new code with 1.5?
 * Cheers
 *  Plugin Author [Chris Scott](https://wordpress.org/support/users/chrisscott/)
 * (@chrisscott)
 * [13 years, 3 months ago](https://wordpress.org/support/topic/plugin-multiple-post-thumbnails-adding-direct-url-src-to-plugin-with-wp_get_attachment_image_src-to/#post-3122791)
 * [@lord_dev](https://wordpress.org/support/users/lord_dev/) 1.5 should go out 
   tomorrow.
 *  Plugin Author [Chris Scott](https://wordpress.org/support/users/chrisscott/)
 * (@chrisscott)
 * [13 years, 3 months ago](https://wordpress.org/support/topic/plugin-multiple-post-thumbnails-adding-direct-url-src-to-plugin-with-wp_get_attachment_image_src-to/#post-3122792)
 * [@lord_dev](https://wordpress.org/support/users/lord_dev/) 1.5 was just released.
   If you have any issues, please update this thread.

Viewing 11 replies - 1 through 11 (of 11 total)

The topic ‘[Plugin: Multiple Post Thumbnails] Adding direct URL src to plugin with
wp_get_attachment_image_src’ is closed to new replies.

 * ![](https://s.w.org/plugins/geopattern-icon/multiple-post-thumbnails_d94965.svg)
 * [Multiple Post Thumbnails](https://wordpress.org/plugins/multiple-post-thumbnails/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/multiple-post-thumbnails/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/multiple-post-thumbnails/)
 * [Active Topics](https://wordpress.org/support/plugin/multiple-post-thumbnails/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/multiple-post-thumbnails/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/multiple-post-thumbnails/reviews/)

## Tags

 * [image source](https://wordpress.org/support/topic-tag/image-source/)
 * [size](https://wordpress.org/support/topic-tag/size/)

 * 11 replies
 * 4 participants
 * Last reply from: [Chris Scott](https://wordpress.org/support/users/chrisscott/)
 * Last activity: [13 years, 3 months ago](https://wordpress.org/support/topic/plugin-multiple-post-thumbnails-adding-direct-url-src-to-plugin-with-wp_get_attachment_image_src-to/#post-3122792)
 * Status: resolved