Add ID # to next_image_link and next_image_link

The WordPress

next_image_link

and

 next_image_link 

are two useful function to display the gallery images in the post, but the default link is un-user-friendly, for some of site, the header section is BIG, that means when ever you click the next image, you have to scroll down to see the image, and then you click the next link to view the next image, you can add the ID to each link, then the visitors can go to the image directly, that’s much better.

If you want to add

#content

to the end of the link location for each previous_image_link() and next_image_link(), you can add the following php code to the functions.php to your theme.

function add_content_hash( $link ) { 
    $link = str_replace("' title='", "#content' title='", $link);
    return $link;
}
add_filter( 'wp_get_attachment_link', 'add_content_hash' );