The new generate_do_template_part action

This action, new to GeneratePress 3 premium update looks like is a game changer! This action will allow us to build post loop templates in Block Elements, and then hook them into the theme.

Currently, there is no UI for the action but you can use some code and, the also new in GP3, Block Element to completely replace the post loop with your own creation. As Tom mentions in this post, he will be introducing Template Tags (like in the current Header Element) into Block Elements in an upcoming GPP update that will allow us to dynamically pull in data from the current post object while using GenerateBlock elements!

Meanwhile, you can still take advantage of the generate_do_template_part action to create some magic. In this example, we are going to replace the 404 page with a custom block element.

Create your beautiful 404 page by going to Appearance -> Elements and setting up a new block element. Set the hook to be a Custom Hook and select generate_do_template_part for Custom Hook Name. Finally, select the 404 template as Location.

Replace 404 page - Custom hook element
Replace 404 page – Custom hook element

Your new block element will now replace the 404 page post loop template!

You can display the search form found on the default 404 page by using a shortcode block. Insert the following code in your functions.php:

function gm_display_search_form() {
    return get_search_form(false);
add_shortcode('display_search_form', 'gm_display_search_form');

Then, insert a shortcode block and enter [display_search_form]. Don’t forget to save the page!

I am really looking forward to the generate_do_template_part action getting more streamlined in the upcoming GPP update and I will be updating the knowledgebase with more articles.

This is great news!