Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author Jeremy Herve

    (@jeherve)

    Jetpack Mechanic ??

    The wp_get_attachment_url filter I mentioned in the other thread you started last week also include a second parameter, the post ID.
    You could consequently get the resized image you need from that post ID, and return it instead of the default URL thanks to the wp_get_attachment_url filter.

    I hope this helps.

    Thread Starter Frank.Prendergast

    (@frankprendergast)

    Hi Jeremy, thank you for responding so quickly – I’m not a developer so I apologise for my fairly basic understanding, I just wanted to check something – the developer who posted the function I mentioned said using wp_get_attachment_url resulted in a loop which is why he filtered wp_get_attachment_link instead – as I mentioned this works until I activate Jetpack tiled galleries – but if I look at filtering wp_get_attachment_url will I run into the same loop issues or does using Jetpack tiled galleries mean those calls in media.php are avoided?

    I initially set a filter on the wp_get_attachment_url hook, and the filter used wp_get_attachment_image_src( post_id, ‘large’ ) to get the URL of the large image size. HOWEVER, this resulted in a loop because wp_get_attachment_image_src() (which is in media.php) calls image_downsize() (also in media.php), which then uses wp_get_attachment_url() to get the URL. Which calls our filter…and so on.

    I do realise this is not plugin support, so your pointers are greatly appreciated.

    Plugin Author Jeremy Herve

    (@jeherve)

    Jetpack Mechanic ??

    Oh, I see. That’s something I didn’t think about.

    Another alternative I can think about would be to set your galleries to link to attachment pages, and then filter the attachment page links like so:

    /**
     * Return links to medium media files in galleries.
     * Only works when the gallery is set to link to attachment pages.
     *
     * @param string $link    The attachment's permalink.
     * @param int    $post_id Attachment ID.
     */
    function jeherve_small_attachment_links( $link, $post_id ) {
    	$image = wp_get_attachment_image_src( $post_id, 'medium' );
    	if ( $image ) {
    		return $image[0];
    	}
    	return $link;
    }
    add_filter( 'attachment_link', 'jeherve_small_attachment_links', 10, 2 );
    Thread Starter Frank.Prendergast

    (@frankprendergast)

    Thank you, I really appreciate you taking the time to respond – I will give this a try…

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Tiled Gallery Jetpack – link to resized image’ is closed to new replies.