Creating gallery from new WP gallery blocks?

contact's Avatar


18 Jun, 2020 08:32 PM

With the "new WP" block, the code of the gallery became much complicated.
Is there any "simple" way to turn a new wp gallery into a slider?

  1. Support Staff 1 Posted by Dmitry Semenov on 19 Jun, 2020 01:51 PM

    Dmitry Semenov's Avatar


    You can do something like:

    function rs_render_gallery( $attributes, $content ) {
            $ids_string = implode (',', $attributes['ids']); ;
        return do_shortcode('[gallery royalslider="YOUR_SLIDER_ID" ids="'.$ids_string.'"]');
    function rs_register_gallery() {
        register_block_type( 'core/gallery', array(
            'render_callback' => 'rs_render_gallery',
        ) );
    add_action( 'init', 'rs_register_gallery' );

    and it'll override Gutenberg gallery to [gallery] shortcode on frontend. Replace YOUR_SLIDER_ID with numeric ID of "gallery" slider. Also make sure that files are included ( ), as auto-detection based on shortcode won't work in this case.

    You might need to modify how IDs are retrieved from Gutenberg block ($attributes['ids'] part), as it might be different depending on your website configuration.

  2. 2 Posted by contact on 19 Jun, 2020 02:48 PM

    contact's Avatar

    ok thanks

Reply to this discussion

Internal reply

Formatting help / Preview (switch to plain text) No formatting (switch to Markdown)

Attaching KB article:


Attached Files

You can attach files up to 10MB

If you don't have an account yet, we need to confirm you're human and not a machine trying to post spam.

Keyboard shortcuts


? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac