Add gallery id to rel attribe of wp_get_attachment_link
That filter passes more arguments than you are using. return apply_filters( ‘wp_get_attachment_link”https://wordpress.stackexchange.com/questions/134811/,”<a href=”https://wordpress.stackexchange.com/questions/134811/$url”>$link_text</a>”, $id, $size, $permalink, $icon, $text ); The second of those is the one you need. So you need to alter you callback to use the second parameter, and alter your add_filter to ask for it by setting the fourth argument to 2. … Read more