Support » Plugins and Hacks » [Resolved] [Plugin: Multiple Post Thumbnails] Adding direct URL src to plugin with wp_get_attachment_image_src

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

  • gabrielstuff


    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);
    				return $image[0];
    				return false;

    I’m happy with it ! Thanks for your work. Please do not hesitate to add this function to your next update.


Viewing 11 replies - 1 through 11 (of 11 total)
  • 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)

    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.

    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:

     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') . '" >';
       echo '</a>';

    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.

    Hi, I found this:


    Which I had missed earlier, and used code modified from here to make my link to larger images work. Thanks!

    Plugin Author Chris Scott


    @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.

    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


    Can you test this out with the following: 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.

    Chris Scott – Works perfectly thanks!!

    When will you release the new code with 1.5?


    Plugin Author Chris Scott


    @lord_dev 1.5 should go out tomorrow.

    Plugin Author Chris Scott


    @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 ‘[Resolved] [Plugin: Multiple Post Thumbnails] Adding direct URL src to plugin with wp_get_attachment_image_src’ is closed to new replies.