- This topic has 8 replies, 4 voices, and was last updated 3 years, 2 months ago by Elvin.
-
AuthorPosts
-
February 14, 2021 at 12:17 am #1657513David
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!
(continued from https://generatepress.com/forums/topic/custom-hooks-2/#post-1657429)February 14, 2021 at 12:20 am #1657518DavidThis reply is only for me to tick the ‘Notify me by email’ box 🙂
February 14, 2021 at 6:23 am #1657708DavidStaffCustomer SupportHi there,
Is the Custom Block added using the Block Element?
If so you can use the same Hook as that, just change the Priority to a lower number ( the default is 10 ) – so setting your other hook priority to 5 for example will position it before.February 14, 2021 at 12:55 pm #1658182DavidHi David
The thing that I want to be hooked is an Element in Generate Press and I want it hooked above a Reusable Block, which is added to each individual post.
February 14, 2021 at 2:13 pm #1658253YingStaffCustomer SupportHi David,
Is the reusable block added manually in to each post content?
If so, do you want to hook content into the post content as well?
Or could you specify where exactly you want the hook to be?
Here’re some documentations that might help you to understand hook better:
https://docs.generatepress.com/article/hooks-element-overview/
https://docs.generatepress.com/article/hooks-visual-guide/February 15, 2021 at 10:49 am #1659378DavidHi Ying
The reusable block is added manually into each post and it’s at the bottom of each post (it’s a related posts block with a title). I want to hook an image above this reusable block – or if not there specifically, somewhere in the post itself.
I’ve tried all of the available options and they place the image somewhere at the top or bottom or the page and one goes in the sidebar but nothing within the content.
February 15, 2021 at 11:41 am #1659433YingStaffCustomer SupportIf that’s the case, the reusable block is inside article, Unfortuanly no hook goes into content.
I would recommend to create a block element using the reusable block, choose
generate_after_content
as hook.Then create another hook for the image, also choose
generate_after_content
as hook, change its priority to 9 so it can be displayed before the reusable block.February 15, 2021 at 12:52 pm #1659535DavidI’m trying the impossible! You have a solution – I might try that.
Thanks
February 15, 2021 at 6:37 pm #1659738ElvinStaffCustomer SupportHi there,
You can actually create a “custom hook” anywhere within the content if you need one.
It’s a bit tedious but consider my answer here:
https://generatepress.com/forums/topic/hook-in-hook/#post-1636333It’s a bit difficult to digest but to put it simply, we’re basically trying to place “hooks” using the shortcode.
This shortcode can be placed above your reusable block, making it a “hook” about the mentioned block.
But I’d recommend doing Ying’s suggestion though. You should add the related post block through a block element hooked to
generate_after_content
rather than adding it as a content. -
AuthorPosts
- You must be logged in to reply to this topic.