Really I'm gonna be crazy :(, After searching for two months no one talking about this issue!!

I'm stuck with that!!

I mange a multi writers blog, and all our users uploading gallery images, and they didn't know the difference between (attachment, media file or none), I'm using Lightbox plugin and working only when images linked to file.

enter image description here

Before WordPress version 5+ I was linked all gallery images to "file" automatically by using this filter below.

add_filter( 'shortcode_atts_gallery',
    function( $out ){
        $out['link'] = 'file'; 
        return $out;

But after WP 5+ how can I make it to work again? I really need to link all gallery images to "media file" automatically!

I hope someone will help me or even giving me the right way.

Thanks for your time.

1 Answer 1


Finally by luck i found the answer by @Tomas

function gallery_template_to_posts() {
    $post_type_object = get_post_type_object( 'post' );
    $post_type_object->template = array(
        array( 'core/gallery', array(
            'linkTo' => 'media',
        ) ),
add_action( 'init', 'gallery_template_to_posts' );

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.