Archived topic
GP Reusable Equivalent
3 replies · Started by Ian on July 5, 2022
Is there an updated method to drop in a "reusable block" that lives within GP or GB?
In the past, I have been using this method to drop content throughout the site: https://generatepress.com/forums/topic/hook/#post-1038253
The block in question is an HR separator. Tried using HTML in a container and creating a Global Style did not work. Also tried creating it as a Local Pattern. This allowed for easy insertion but when we update the original Local Pattern, already inserted iterations throughout the site does not update itself.
Do not want to use Wordpress Reusable Blocks as it's very unstable. Any ideas?
Hi Ian,
You would still need to use a Portable Hook to do as such.
If you want, you can try adding this Snippet to the one provided by David:
add_filter( 'generate_hooks_list', function($hooks){
$hooks['content']['hooks'][] = 'custom_shortcode_hook';
return $hooks;
}, 99,1 );
This code adds the custom_shortcode_hook to the dropdown list of available hooks so that you wouldn’t have to type it in your element.
Hope this helps!
I see. I have added the code and understand how it works. So I would have to create as many functions as I had elements that needed to be pulled?
Was really hoping for a GP way to implement a reusable block. Seems like Global Styling / Asset is so close. Can you add this request to the roadmap and see if it gets traction?
In terms of the code I provided, you only need to run it once. For instance, if you’re adding two custom portable hooks - your_hook_name and your_hook_name2, the code would simply be:
add_filter( 'generate_hooks_list', function($hooks){
array_push($hooks['content']['hooks'],'your_hook_name','your_hook_name2');
return $hooks;
}, 99,1 );
With regards to feature requests, you can create one here: https://community.generateblocks.com/c/feature-requests/6
Hope this clarifies!