[Plugin: Multiple Post Thumbnails] Adding direct URL src to plugin with wp_get_attachment_image_src
-
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.
https://www.ads-software.com/extend/plugins/multiple-post-thumbnails/
Viewing 11 replies - 1 through 11 (of 11 total)
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.