• Resolved outdoorsdev1

    (@outdoorsdev1)


    I’m creating a website with this plugin, i’m using the generatepress theme with generateblocks, which has a custom image block which is really customizable.

    I understand that for this plugin to work, that it needs a figure block with the class wp-block-image, then an a href to the image, then an img inside.

    I can’t get this to work. I tried modifying the plugin code itself to add

    .gb-block-image

    to the $baguettebox_selector = apply_filters list

    and add the below into the $baguettebox_enqueue_assets list

    has_block( ‘generateblocks/image’ ) ||

    but the image still seems to just link to original image.

    here are two urls affected, you can only use the link to these once so don’t close them, I don’t want the site indexed

    Note one is a custom post type, but the first is a blog. in the blog there are two images, one is a normal wordpress block, the next a generatepress image block

    Any help is appreciated 🙂

    • This topic was modified 1 year, 6 months ago by outdoorsdev1.

    The page I need help with: [log in to see the link]

Viewing 13 replies - 1 through 13 (of 13 total)
  • Plugin Author Johannes Kinast

    (@goaroundagain)

    Hi @outdoorsdev1,

    I just tagged version 1.13 with support for GenerateBlocks. Has been on my to-do list anyway.

    Is it possible that the image in the /card/ post is in a reusable block?

    In the Style Guide the link to the full is missing for the GenerateBlocks image.

    Thread Starter outdoorsdev1

    (@outdoorsdev1)

    Thanks for pushing the update, that has fixed the issue with the single post and you were right that I hadn’t linked that image to its source. I appreciate the prompt reply and the plugin itself 🙂

    Yes, this image is in a reusable block which has a dynamic link to the image and also the source in a GB image block. They’re pulled from ACF data if that’s of any use.

    Plugin Author Johannes Kinast

    (@goaroundagain)

    The problem is that the has_block function from WordPress just checks the main post, not an embedded reusable block (which is a post, too). There is a workaround: https://github.com/goaround/gallery-block-lightbox/issues/11 But presently this comes with a performance decrease. I still hope WordPress itself will fix it.

    You can add the following snippet to functions.php:
    add_filter( 'baguettebox_enqueue_assets', '__return_true' ); and the script & style will load everywhere. This is a easy fix, if you use the Gallery on every page anyway.

    Thread Starter outdoorsdev1

    (@outdoorsdev1)

    This is again really helpful, thanks.

    As i’d probably be using this on most pages, is it possible to just call it on all blog or specific post types (i use a custom post type) instead of running a check?

    Thread Starter outdoorsdev1

    (@outdoorsdev1)

    Also found this

    https://github.com/WordPress/gutenberg/issues/18272

    this checks to see if a block is reusable, if I add this using code snippets would it be less resource intensive than your workaround?

    function has_reusable_block( $block_name, $id = false ){
        $id = (!$id) ? get_the_ID() : $id;
        if( $id ){
            if ( has_block( 'block', $id ) ){
                // Check reusable blocks
                $content = get_post_field( 'post_content', $id );
                $blocks = parse_blocks( $content );
    
                if ( ! is_array( $blocks ) || empty( $blocks ) ) {
                    return false;
                }
    
                foreach ( $blocks as $block ) {
                    if ( $block['blockName'] === 'core/block' && ! empty( $block['attrs']['ref'] ) ) {
                        if( has_block( $block_name, $block['attrs']['ref'] ) ){
                           return true;
                        }
                    }
                }
            }
        }
    
        return false;
    }
    Thread Starter outdoorsdev1

    (@outdoorsdev1)

    In testing, now on that page the assets to load to bring up the lightbox but not the image itself?

    https://pastebin.com/YGL67pQS

    Plugin Author Johannes Kinast

    (@goaroundagain)

    @outdoorsdev1 this is the workaround I mean. But it runs parse_blocks, which is a heavy function, on every check for every reusable post for every block.

    Plugin Author Johannes Kinast

    (@goaroundagain)

    @outdoorsdev1 try

    add_filter( 'baguettebox_enqueue_assets', function ($load) { return $load ?: is_singular('card'); } );

    If the name of the post type is card

    Thread Starter outdoorsdev1

    (@outdoorsdev1)

    I very slightly changed that to be

    add_filter( 'baguettebox_enqueue_assets', function ($load) { return $load ?: is_singular(array('card', 'post' )); } );

    so it works for posts and card type posts.

    Still though, on card pages only the lightbox comes up, but not the image?

    Plugin Author Johannes Kinast

    (@goaroundagain)

    Make sure to clear the Cache or restart PHP

    Thread Starter outdoorsdev1

    (@outdoorsdev1)

    That doesn’t seem to have changed anything. The post does pull from an element within generatepress if that makes a difference, maybe the element (a content template) needs to be referenced too?

    Thread Starter outdoorsdev1

    (@outdoorsdev1)

    When inspecting on this page https://pastebin.com/gWT6ZeCE

    it looks like there is a javascript error in the console when clicking the image

    Uncaught TypeError: Node.removeChild: Argument 1 is not an object.

    There are a couple of posts on the homepage you can check out that seem to be fine.

    Plugin Author Johannes Kinast

    (@goaroundagain)

    @outdoorsdev1 it seems to be an error inside baguettBox.js: https://feimosi.github.io/baguetteBox.js/

    On my test site it works fine with GeneratePress. I can’t help you here anymore. Sorry.

Viewing 13 replies - 1 through 13 (of 13 total)
  • The topic ‘custom post type and generatepress block’ is closed to new replies.