Whenever you add a image gallery to a post, the images automatically link to the image attachment pages. This is not ideal, because I want to use Fancybox so the user can cycle through the images.
I tried the following code to let the images link to the files by default, but this doesn’t seem to work for galleries. Any suggestions on how to set the default link type to “file” for image galleries?
I would be even happier if the image attachment page wouldn’t be available at all (on galleries an regular images). I don’t really like this feature.
/** * Set default image link type to file */ function tp_set_default_link_type() { update_option( 'image_default_link_type', 'file' ); } add_action( 'after_switch_theme', 'tp_set_default_link_type' );
Thanks in advance!
3 Answers
You can override the gallery shortcode link
attribute with:
add_filter( 'shortcode_atts_gallery',
function( $out ){
$out['link'] = 'file';
return $out;
}
);
This means that even if your shortcodes are:
the gallery output will always be generated as if you used link="file"
.