Multiple Post Thumbnails
[resolved] Adding direct URL src to plugin with wp_get_attachment_image_src (12 posts)

  1. gabrielstuff
    Posted 3 years ago #

    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.


  2. lord_dev
    Posted 3 years ago #

    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)

  3. gabrielstuff
    Posted 3 years ago #

    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.

  4. charmedworks
    Posted 3 years ago #

    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>';
  5. charmedworks
    Posted 3 years ago #

    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.

  6. charmedworks
    Posted 3 years ago #

    Hi, I found this:


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

  7. Chris Scott
    Plugin Author

    Posted 2 years ago #

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

  8. lord_dev
    Posted 2 years ago #

    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!

  9. Chris Scott
    Plugin Author

    Posted 2 years ago #

    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.

  10. lord_dev
    Posted 2 years ago #

    Chris Scott - Works perfectly thanks!!

    When will you release the new code with 1.5?


  11. Chris Scott
    Plugin Author

    Posted 2 years ago #

    @lord_dev 1.5 should go out tomorrow.

  12. Chris Scott
    Plugin Author

    Posted 2 years ago #

    @lord_dev 1.5 was just released. If you have any issues, please update this thread.

Topic Closed

This topic has been closed to new replies.

About this Plugin

  • Multiple Post Thumbnails
  • Frequently Asked Questions
  • Support Threads
  • Reviews

About this Topic