Site logo

Archived topic

How Do I Create Custom Hooks

8 replies · Started by David on February 14, 2021

Viewing posts 1–9 of 9

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)

This reply is only for me to tick the 'Notify me by email' box :)

Hi 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.

Hi 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.

Hi 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.

If 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, choosegenerate_after_contentas 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.

I'm trying the impossible! You have a solution - I might try that.

Thanks

Hi 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-1636333

It'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.

This archived topic is closed to new replies.