Skip to content
Advertisement

Force WordPress Gallery to Use Media File Link instead of Attachment Link

Is there a filter or hook to force WordPress Galleries to use the Media File Link instead of the Attachment Link. I can not trust my client to manually switch the setting while creating the gallery. http://cl.ly/image/2g1L1G2c2222

Brings up another issue of why Media File is not the default type.

Advertisement

Answer

You can basically ovveride the default gallery shortcode .

remove_shortcode('gallery', 'gallery_shortcode'); // removes the original shortcode
    add_shortcode('gallery', 'my_awesome_gallery_shortcode'); // add your own shortcode

    function my_awesome_gallery_shortcode($attr) {
    $output = 'Codex is your friend' ;
    return $output;
}

Inside the custom function you could set whatever you want .. look at the original gallery shortcode .

Another way is to actually filter the attributes ( if you will go to the above link, you will see a filter hook )

add_shortcode( 'gallery', 'my_gallery_shortcode' );

function my_gallery_shortcode( $atts )
{
    $atts['link'] = 'file';
    return gallery_shortcode( $atts );
}
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement