Are you a GenerateCustomer?

Do you have an active GP Premium or GenerateBlocks Pro license key?

Create a GenerateSupport account for GeneratePress and GenerateBlocks support in one dedicated place.

Create an account
Already have a GenerateSupport account? Login

Just browsing?

Feel free to browse the forums. Support for our free versions is provided on WordPress.org (GeneratePress, GenerateBlocks).

Want to become a premium user? Learn more below.

Insert a block into all posts?

  • Hello! Is there a simple way to insert a block into all posts?

    Backstory: I have 400+ posts on my website. I just launched an ecommerce store, and would like to insert a block into every post. The block would feature a few products and let people know we have a store, and here are a few of our top sellers. I’d like it to show up around 30% through the article. Or we could do after 10 paragraphs, or whatever.

    Is there an easy way to do that? Hooks, reusable block patterns, etc?

    Thank you!

  • Hi there,

    GP does not have a built-in hook in the content area, you will need to create a custom hook.

    Check this solution, you need to change the number 6 to 10 in the code, and sixth to tenth
    https://generatepress.com/forums/topic/show-element-after-specific-paragraph/#post-2067989

    The custom hook name would be after_tenth_paragraph.

  • Forgive me, but could you explain what I’m supposed to do with that code? I assume I add it as a PHP function/snippet, right? After that I’m not clear on
    1) how to create the hook, and
    2) how to tell the hook to pull my reusable block

    Thanks!

  • 1) how to create the hook, and

    The hook is created by the code.

    2) how to tell the hook to pull my reusable block

    Add your content to a block element – hook at appearance > elements, and the hook name will be after_tenth_paragraph.

  • Excellent, thank you!

  • Sorry last question – If I wanted to insert another block after, say, paragraph 25, would I just repeat the entire process (and swap out “10” and “tenth” with 25/25th)? Thanks!

  • That’s correct, just make sure the 2 functions have different names, as every function name has to be unique.

  • Thank you!

  • No Problem 🙂

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