Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

When [gallery link="file"] is used, it calls the original image file source.

It it possible to create a shortcode filter that links to a specific size, like:

[gallery link="medium"]

or

[gallery link="custom-size-name"]

(referring to an additional image size created with add_image_size() in functions.php.)

share|improve this question
    
core.trac.wordpress.org/ticket/18178 is different patch for [gallery] shortcode enhancement. From the looks of it, I think patching this feature into the core shouldn't be much of an issue complexity wise. –  lkraav Mar 15 '12 at 21:10
    
+1. even 3 years later, and after the recent gallery revamps, this is still an issue - especially if you use a lightbox in conjunction with the wordpress gallery. there needs to be a size option here to stop users having to download 4 meg images to view in a 800x600 lightbox... –  jammypeach Oct 7 at 9:51

2 Answers 2

Short of de-registering the built in shortcode tag, copying the function and re-registering it with some modifications you could filter on wp_get_attachment_link. The problem is this affects everywhere that function is used.

Saying that it might not be such a bad thing:

add_filter( 'wp_get_attachment_link', 'my_attachment_link', 10, 6 );
function my_attachment_link( $link, $id, $size, $permalink, $icon, $text ) {
    if ( !is_admin() ) {
        // if we're linking to the file itself
        if ( ! $permalink )
            $link = preg_replace("/href=\'([^\']+)\'/", "href='" . wp_get_attachment_image_src( $id, 'my-custom-size', false ) . "'", $link );
    }
    return $link;
}

This will override any links generated to the original size file on the front end with a link to the size you specify in the second argument in wp_get_attachment_image_src().

share|improve this answer
    
Just realised this is basically what the oikos.org.uk example is –  sanchothefat Mar 8 '12 at 18:35

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.