Can anyone help me filter wp_get_attachment_link so that a particular occurence of it links to the ‘medium’ or other size image rather than the full size.
I have the following in a page template:
$args = array( 'post_type' => 'attachment', 'numberposts' => -1, 'post_status' => null, 'post_parent' => $post->ID );
$attachments = get_posts($args);
if ($attachments) {
foreach ( $attachments as $attachment ) {
echo wp_get_attachment_link( $attachment->ID , array(150,150) );
}
}
I can add a filter to add class or rel but I can’t find anyway to alter the default (as originally uploaded) full size image linked to in the template ….
The above works fine with colorbox (not plugin) to create a lightbox, but if a user uploads a very large image (ie: 4000×4000+ pixels), the link will load too slowly and I don’t want the public to be able to download a print quality image from the lightbox..
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:
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….
You can specify the size you want to link in the
wp_get_attachment_link
function, isn’t the code you posted working?Try:
I am not sure if you can filter the links within the content in PHP, but you could use jQuery to replace the href of each of the links, selecting them based on those rel and class values you mentioned.