Archived topic
Custom hooks
11 replies · Started by Vl on April 16, 2019
Hi!
I need to add a hook to a specific place on the page. I tried to do this with a Custom hook, but I can not understand what I have to write in the line: "Custom Hook Name"?
How to put a custom hook on a specific place on the page?
Thanks.
Hi there,
Hooks have a specific place in a Template you can see the majority of them in these visual guides:
https://docs.generatepress.com/article/hooks-visual-guide/
Custom Hook fields are used for hooks that aren't listed or those that are within another plugin.
Thanks for the answer.
Can I attach a hook to an ID or class?
This is necessary in order to insert a hook anywhere on the page, for example, inside an article.
Unfortunately not - that would be pretty cool :)
What you can do is filter the_content(). Example here was used to add the featured image after the 2nd paragraph:
https://generatepress.com/forums/topic/featured-image-inside-the-article/#post-708308
Thanks for the answer.
I have another question not about Custom hooks.
For example, the site has the following structure:
http://www.site.com/page1/page2/page3/
Is it possible to insert a hook on the "page1" so that it is automatically inserted on the "page2" and "page3"?
Hooks are a part of the Post Template. So if you add content to a Hook and set that to display on All Pages for example then that content would appear on all Pages including paginated ones.
That is, I can add a hook only to all pages or to individual pages that I choose in the settings.
And I cannot add a hook to the parent page so that it is automatically added to all child pages.
This is true?
Thats correct. Currently you would have to select the child pages in the display rules as well.
Thank you.
Glad to be of help
Hi there
I want to add a custom hook to my posts above a custom block that is at the bottom of each post. I have tried adding codes from the custom block and others from inspecting the items on the page.
Am I adding the wrong code or is it not possible to create a hook anywhere?
I was trying all sorts with 'generate_before...'
(I did install Code Snippets plugin, but didn't know where to start)
Thanks for all your tutorials and replies - GP Rocks!
Hi David,
Please open a new topic and link us to the page in question.
Thanks!