[Support request] How Do I Create Custom Hooks

Home Forums Support [Support request] How Do I Create Custom Hooks

Home Forums Support How Do I Create Custom Hooks

Viewing 9 posts - 1 through 9 (of 9 total)
  • Author
    Posts
  • #1657513
    David

    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)

    #1657518
    David

    This reply is only for me to tick the ‘Notify me by email’ box 🙂

    #1657708
    David
    Staff
    Customer Support

    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.

    #1658182
    David

    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.

    #1658253
    Ying
    Staff
    Customer Support

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

    #1659378
    David

    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.

    #1659433
    Ying
    Staff
    Customer Support

    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.

    #1659535
    David

    I’m trying the impossible! You have a solution – I might try that.

    Thanks

    #1659738
    Elvin
    Staff
    Customer Support

    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.

Viewing 9 posts - 1 through 9 (of 9 total)
  • You must be logged in to reply to this topic.