[Resolved] Question about GP 3.0 and generate_do_template_part

Home Forums Support [Resolved] Question about GP 3.0 and generate_do_template_part

Home Forums Support Question about GP 3.0 and generate_do_template_part

Viewing 14 posts - 1 through 14 (of 14 total)
  • Author
  • #1429816


    I’m curious about the new generate_do_template_part in GP 3.0. I’m looking to redesign my current website and move it over to GP, so I am testing out GP. So far I’m really liking the focus on clean and fast code!

    Some questions:

    In the GP 3.0 Alpha launch post it says “Imagine building your custom templates as Block Elements and dynamically displaying them in place of the standard theme loop across your site.”

    I may be way off here, and please correct me if I am but:

    1. Does this mean that we will be able to for instance design custom category pages with the block editor? And have control of the layout of the loop itself on those pages?

    2. If so, will it work with the visibility controls in GPP so that I can for instance have different category loop layouts for different categories?

    3. Won’t this require a sort of display posts block, to replace the loop with?

    4. What about dynamically pulling in metadata such as the current category etc?

    4. It looks as if the generate_do_template_part in GP 3.0 opens up a lot of possibilities, but to really use them I guess we will need a new version of GPP? Is that correct, and if so when can we expect it? πŸ™‚

    Great job on GP 3.0. I’ll continue to test it out and let you know if I discover anything buggy πŸ™‚

    Best Regards,


    Lead Developer
    Lead Developer

    Hi there,

    Great questions!

    1. That’s correct. This action will allow us to build post loop templates in Block Elements, and then hook them into the theme.

    2. Full control with Display Rules – different designs for different archives etc..

    3. Not necessarily. We’re introducing Template Tags (like in the current Header Element) into Block Elements in GPP 1.12.0. This will allow you to dynamically pull in data from the current post object while using the Headline Block in GenerateBlocks. Post titles, post meta etc..

    4. See above.

    5. Yes, if you’re wanting a full UI to build with. You can, of course, use code:

    // Disable the core template part on the blog page.
    add_filter( 'generate_do_template_part', function( $do ) {
        if ( is_home() ) {
            return false;
        return $do;
    } );
    // Add our own.
    add_action( 'generate_before_do_template_part', function() {
        if ( is_home() ) : ?>
            <article <?php post_class(); ?>>
                <div class="inside-article">
                    <h1><?php the_title(); ?></h1>
                    <a class="button" href="<?php the_permalink(); ?>">Read more!</a>
        <?php endif;
    } );

    It’s basically a way to replace the theme loop without using child theme files.

    Hope this helps! Thanks for testing 3.0 πŸ™‚


    That sounds fantastic, Tom!

    I’m very excited to start playing with all the new functionality πŸ™‚


    Lead Developer
    Lead Developer

    Definitely a lot of cool things that can be done now! πŸ™‚



    I have recently upgraded to GP premium 1.12.0-alpha.1 and I’m not able to see any option for generate_do_template_part or generate_menu_bar_items in the elements hook options. Am I possibly missing something or am I just to premature to test these features?

    Testing GP 3.0 and aside from my confusion above, so far so good. Thanks!

    Customer Support

    Hi there,

    generate_menu_bar_items is a standard action hook – it will be added to the Elements list in the next update. In the meantime you can manually add it by selecting the Custom Hook.

    generate_do_template_part is more complicated then that and will be something that GPP will integrate in a future update. In the meantime the code method Tom provided is the way to go.


    That’s great! Thanks David. Really pleased with what you guys have come up with for 3.0

    Keep up the good work!

    Customer Support

    Glad to be of help – and thanks for the great feedback.


    Just to make sure I fully understand what’s available with generate_do_template_part currently.

    It sounds like using Elements linked to generate_do_template_part you can use the block editor to replace the loop for specific content.

    We need a new GPP to be able to use a block element with dynamic content (i.e. a block layout where you can replace title, excerpt, post, categories, etc with data at run time).

    Is there any way in PHP code to tell GP to display a block element or are we limited to using the Elements UI to select where an element shows?

    Lead Developer
    Lead Developer

    You could definitely use code to insert a Block Element into that hook. The issue right now is making it so the Block Element works nicely within the loop. There are some issues there we need to figure out before it will work perfectly.


    i cannot find the documentation for the generate_do_template hook. is there a guide available?

    Lead Developer
    Lead Developer

    Hi there,

    We’re working on a documentation article with some examples.

    For now, the post above explains the main concept: https://generatepress.com/forums/topic/question-about-gp-3-0-and-generate_do_template_part/#post-1429909

    Let me know if you are trying to do some specific and I’ll do my best to help πŸ™‚


    Here’s another example of the power of this new capability in GP 3.0, which David assisted with…

    It easily swaps out the (poor) default WordPress search function for a much better Google custom search engine:


    With just those few lines of code, your search capability is seamlessly upgraded sitewide. Wow.

    Lead Developer
    Lead Developer

    Thanks for sharing! That’s awesome πŸ™‚

Viewing 14 posts - 1 through 14 (of 14 total)
  • You must be logged in to reply to this topic.