最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

How to link Gutenberg Gallery images To Media file automatically?

programmeradmin1浏览0评论

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' );
发布评论

评论列表(0)

  1. 暂无评论