-
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
to10
in the code, andsixth
totenth
https://generatepress.com/forums/topic/show-element-after-specific-paragraph/#post-2067989The 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 blockThanks!
-
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 🙂
- You must be logged in to reply to this topic.