WP Gallery shortcode link to file

Hi,

As standard the [gallery]-shortcode in wordpress links to the attachment page for the image. If we want it to link to the full version of the images we need to manualy add link="file" to the shortcode.

Do you know if it possible to make the gallery-shortcode link to the file as standard? (With the use of Filters or other methods)

Thanks,
Erlend/Smart Media AS

  • Mike
    • New Recruit

    Hi @smartmediaas

    Thanks for posting!

    I've done a quick Google search for you to see if I can help out and I found this code:

    add_shortcode( 'gallery', 'file_gallery_shortcode' );
    
    function file_gallery_shortcode( $atts ) {
        $atts['link'] = 'file';
        return gallery_shortcode( $atts );
    }

    This intercepts the shortcode and adds "link=file", I tried it on my test site and it seemed to work fine.

    Add the code to the bottom of your functions.php and it should work for you.
    Be aware that it won't add link=file to the shortcode, but will have the desired results.

    I hope this helps!

    Cheers,
    Mike

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.