Overriding default gallery in Gutenberg

jason's Avatar


06 Feb, 2019 08:46 PM

I've updated the software to the latest version, but our Royal Slider doesn't appear to override the block gallery function any longer. I now see the RoyalSlider block in the editor, but there are no options on the right side and it just says no sliders available.

We have been using NRS for years to override the default WP gallery with a carousel slider. Any suggestions for a workaround or a step we are missing in the process?

  1. Support Staff 1 Posted by Dmitry Semenov on 06 Feb, 2019 10:17 PM

    Dmitry Semenov's Avatar


    Default Gutenberg gallery block does not support overriding, https://github.com/danielbachhuber/gutenberg-migration-guide/blob/m... They promise to add post_gallery filter support in the future, but for now there is no such option and there is no ETA when it'll be added.

    But [gallery] shortcode can still be overridden, as it's unchanged. To add it to Gutenberg you may use either "shortcode block" or "classic editor" block.

    Or you may keep using old WordPress post editor by installing Classic Editor plugin https://wordpress.org/plugins/classic-editor/

  2. 2 Posted by josh on 03 Apr, 2019 08:22 PM

    josh's Avatar

    How do I use a shortcode with an existing gallery created in Gutenberg?
    When I click on the block HTML, I do not see a gallery ID.

  3. Support Staff 3 Posted by Dmitry Semenov on 03 Apr, 2019 08:26 PM

    Dmitry Semenov's Avatar

    Gutenberg does not allow to convert gallery Block to gallery Shortcode, as far as I know. So if you need specifically [gallery] shortcode - you'll need to use "shortcode" block and add gallery manually inside it.

  4. 4 Posted by theMikeD on 20 Aug, 2019 10:07 PM

    theMikeD's Avatar


    Would this do the trick? I rely upon over-riding default galleries with RS, so this one issue will force me to hold back switching to gutenberg.

    Happy to help do the coding if you point me in the right direction.

  5. Support Staff 5 Posted by Dmitry Semenov on 21 Aug, 2019 03:19 AM

    Dmitry Semenov's Avatar


    if you'll be able to retrieve attachment ids and replace HTML output of the default block, you may use this technique to generate RoyalSlider - http://help.dimsemenov.com/kb/wordpress-royalslider-tutorials/wp-cr...

    And thanks for the link, I'll investigate.

  6. 6 Posted by Sas on 02 Oct, 2019 03:30 PM

    Sas's Avatar
  7. 7 Posted by theMikeD on 10 Sep, 2020 07:34 PM

    theMikeD's Avatar

    Is there a solution to this yet?My hack is the following:

    namespace CNMD\RoyalSlider;
    class Blocks {
         * Blocks constructor.
        public function __construct() {
            add_filter( 'render_block', array( $this, 'gallery_block_override' ), 11, 2);
         * Over-ride the render for specific blocks as required.
         * @param string $block_content The block content about to be appended.
         * @param array  $block         The full block, including name and attributes.
         * @return string
        public function gallery_block_override( string $block_content, array $block ): ?string {
            if ( "core/gallery" !== $block['blockName'] ) {
                return $block_content;
            if ( ! array_key_exists( 'attrs', $block ) || ! is_array( $block['attrs'] ) || ! array_key_exists( 'ids', $block['attrs'] ) || ! is_array( $block['attrs']['ids'] ) ) {
                return $block_content;
            return do_shortcode('[gallery royalslider="1" ids="' . implode(',', $block['attrs']['ids']) . '"]');

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