Archived topic
Add reusable Gutenberg Block via Hook in Generatepress Elements
14 replies · Started by Michael on August 5, 2019
Hey there,
My scenario: I created a reusable Gutenberg block (a separator with some svg content).
Now I want to add that reusable block with a hook so the separator also displays on archive and single post pages.
But how can I achieve that with the Elements > Hook Settings?
What I don´t get is how I can "print" in or add the reusable block via function in a clean way.
Do you have a hint in the right direction?
Thank you.
Best regards
Mike
Hi there,
as the Re-usable block is a post type then you can try this:
<?php
// get reusable gutenberg block:
$get_block = get_post( XXXX );
echo apply_filters( 'the_content', $get_block->post_content );
?>
Replace XXXX with the ID of the re-usable block.
However, this will not load dynamic CSS styles - fine if its a core block but you may see a loss of styling if 3rd party blocks are used.
Hi David,
awesome. That worked.
Thank you very much!
Best regards
Mike
Great! - glad to be of help
Sorry for reopening the thread. I have tried the solution using GenerateBlocks that have been converted to reusable blocks but the whole layout and styling have disappeared. I guess it's what you mentioned, David. Is there going to be a solution to this for GB?
Unfortunately that method only works with blocks where inline styles or static stylesheets are used. There isn't a simple solution to getting the dynamic CSS GB uses, but we are working on something in GP to resolve that.
Oh, that's great, thanks!
You're welcome
Hello.
Unfortunately that method only works with blocks where inline styles or static stylesheets are used. There isn’t a simple solution to getting the dynamic CSS GB uses, but we are working on something in GP to resolve that.
Do you have some news about this solution? It would be great to hear a positive answer or at least an estimative deadline for that. Getting the dynamic CSS GB uses would be steroids for designers.
Thank you!
Hi there,
it will be a primary feature in GP Premium 1.11. No definitive time line on that update but i would expect in the next couple of months.
Hi there,
Im trying to get this but is not working for me.
Frontend result:
Hi there,
you need to check Execute PHP when adding PHP to a Hook element.
Thanks!
Any more question, please.
I've made new Custom Post Type with Jet Engine plugin.
So, how i can custom the archive page from my new Custom Post Type in Generate Press with Gutenberg??
With Elementor is possible, but, in Gutenberg with GeneratePress?
Can you raise a new topic for this question.