Archived topic
Hook after title on search page
10 replies · Started by Fabien on August 16, 2021
Hi,
Can you please confirm that at the moment it's impossible to hook content below the title (or before the loop) of the search page ? Will it be possible with GP 3.1 ?
Thanks
Hi Fabien,
You can try the before_do_template_part" hook, assign it tosearch results`.
Let me know if it works.
Hi Ying,
It doesn't work as expected. With generate_before_do_template_part, the hook is inserted in all search results posts. I just want to add something between the PAGE title "Search result for ..." and the results loop. I guess I have to wait for 3.1. Correct ?
Give generate_before_main_content a try, it should add the content before the search result title.
Then if you can link us to your site, we should be able to provide some CSS to bring it below the title.
Let me know :)
Bumping this since 3.1 alpha has been released.
I've been trying to hook using generate_before_loop but it still above the page title.
Maybe there is something to do using generate_search_title_output ?
Ok, I've fixed using a 20 priority
Hi Fabien,
There's no hook directly after the search title as shown here -
https://github.com/tomusborne/generatepress/blob/b60b853630da6d9015722da903e53c8064148b0a/search.php#L27-L39
The way to go is either by setting up a child theme for search.php template just to add a hook after the search page title or
Go with Ying's advice and move the element you're trying to hook using order.
Hi Elvin,
Please read above. I was mentioning GP 3.1 where the generate_before_loop was introduced. It works using a priority 20 ;-)
Ah right. checked again and found it. doh.
Thanks for letting us know. Glad you got it sorted. :D
I was looking for the same solution and was also specifically looking for generate_before_loop in order to display something between the page title and the search results.
The interesting thing is that when you create a new Hook the generate_before_loop hook is not in the dropdown list to choose from. Instead, you need to use it using a custom hook and then enter the name, and then it works just fine!
Might be an idea though to add it to the dropdown list?
(I only found it because I started Googling for "generatepress generate_before_loop")
Hi there,
yeah we don't include all the Hooks in the list, especially those that may 'cause issues' if some types of code are added.
We'll take it under consideration for the next update :)