Archived topic
Generate_before_loop not showing in elements hook section.
6 replies · Started by Josh on October 11, 2022
When I try to create a new elements/hook I want to place it at before the loop of my archive page.
In the archive I see :do_action( 'generate_before_loop', 'archive' );
however when I look in the hook location of elements, only generate_after_loop shows.
How can I add content between the title of the archive page and the content loop? This is for archive-product, which is woocommerce. Right now if I keep do_action( 'generate_archive_title' ); in my template it shows "This is where you can browse products in this store." I want to replace that content with my own.
I chose "custom hook" and added generate_before_loop, which seemed to work but it seems "hackish".
Hi Josh,
To clarify, are you referring to the Shop/Product Archive pages?
If so, here's an article you may refer to for hooks you may use there: https://www.businessbloomer.com/woocommerce-visual-hook-guide-archiveshopcat-page/
Based on your description, you can try: woocommerce_before_shop_loop
I tried that loop. No love. Why doesn't generate_before_loop show up in elements hooks?
Are you referring to why the Hook isn't appearing on the Shop page? That hook isn't available there. The shop page uses archive-product template from WooCommerce. It's not controlled by GeneratePress.
For reference, can you provide the specific link to the page in question?
I created a page based off archive.php. It includes content-product.php (which is based off content.php) which includes content-product-archive.php (this is a wordpress file). In content-product.php There is a line do_action( 'generate_before_loop', 'archive' );
I'm trying to use that hook to add my paragraph.
When I go into elements and create a hook-type element, one of the drop downs is "hook". In that select list there is no generate_before_loop. To use this element I need to choose custom hook and then in the new text field I am typing generate_before_loop. I'm just curious why a hook that is part of generate press isn't listed there. Is that hook not designed for this usage?
Hi there,
we don't list all the hooks in the Elements module, sometimes this is because the Hook as a very specific purpose and we don't want it exposed, other times we have just not updated GP Premium to include it. In this case its probably a little of the former but mainly the latter.
So using the Custom Hook type in this case is the way to go for now.
Thanks David AND Fernando!