Change image link: wp_get_attachment_link

I think I’ve answered my own question sort of….

As I was using a child theme of Hybrid I activated the cleaner gallery extension in the functions.php file: add_theme_support( 'cleaner-gallery' );

Then, based on the topic here I created my own filter:

add_filter( 'cleaner_gallery_image', 'my_gallery_image', 10, 4 );
function my_gallery_image( $image, $id, $attr, $instance ) {

        $post = get_post( $id );
        $image_src = wp_get_attachment_image_src( $post->ID, 'medium' );
        $image_thumb = wp_get_attachment_image_src( $post->ID, 'Custom Thumb' );
        $title = esc_attr( $post->post_title );

        $image = "<a href="https://wordpress.stackexchange.com/questions/24260/{$image_src[0]}"><img src="{$image_thumb[0]}" border="0"></a>";

    return $image;
}

There are still things that are not right such as the title, but it answers the original question, though I’m sure it could be improved on as I’m rather going by the seat of my pants….

Leave a Comment