problem overwriting wp gallery in UX blocks (Flatsome)

artsite's Avatar

artsite

22 Jul, 2021 09:01 AM

I use Flatsome (and Classic editor) and so far the overide WP Gallery is not working in flatsome UX Blocks??
I have seen code for guttenberg blocks - is it the same for ux? Do I need to change something?

*do you mean create a slider called "gallery" ? which in my case would have to become "2" (but "slide config" AKA "1" works for me)

do I do this inside the Flatsome theme functions? And is it only the royal slider number that has to be changed?
Also If I check the option to include JS/CSS files on all pages wont this slow down my page (ref speed test google) ?

your text:
WordPress RoyalSlider Advanced → [WP] Overriding default Gutenberg gallery block
To override the default Gutenberg gallery with the RoyalSlider on the frontend:
1. Create "gallery" type of slider.*
2. Add the code below to your theme functions.php.
3. Replace royalslider="1" with the ID of the slider that you created.
4. Go to RoyalSlider Settings page and check an option to include JS/CSS files on all pages (as auto-detection of the shortcode will not work).

function rs_override_gallery_block($block_content, $block) {
        if ( $block['blockName'] !== "core/gallery" ) {
            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']) . '"]');
}
add_filter('render_block', 'rs_override_gallery_block', 11, 2);

  1. Support Staff 1 Posted by Dmitry Semenov on 22 Jul, 2021 12:17 PM

    Dmitry Semenov's Avatar

    Hello,

    do I do this inside the Flatsome theme functions? And is it only the royal slider number that has to be changed?

    The PHP can be added to your theme functions.php, also some themes have a special place for such snippets, and there are plugins like https://wordpress.org/plugins/code-snippets/

    Also If I check the option to include JS/CSS files on all pages wont this slow down my page (ref speed test google) ?

    It won't significantly affect the page performance, as files are cached.

    I can't answer your questions specific to the flatsome theme, as I haven't used it. The code that you posted override default WordPress Gutenberg gallery block.

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

Generic

? 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