admin管理员组

文章数量:1388110

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.

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.

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.

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.

Share Improve this question asked Mar 14, 2019 at 13:22 Adham MohamedAdham Mohamed 1853 silver badges16 bronze badges
Add a comment  | 

1 Answer 1

Reset to default -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' );

本文标签: How to link Gutenberg Gallery images To Media file automatically