-
Hi – is there a way a can create a small banner at the end of blog posts that are only in one category?
Thanks,
Sam -
Fernando
Hi Sam,
Yes, that’s possible.
You may create a Block Element – Hook. Reference: https://docs.generatepress.com/article/block-element-hook/
Here’s a visual guide of hooks you can use: https://docs.generatepress.com/article/hooks-visual-guide/
In the Display rule settings, you can choose a specific page or set of pages to ensure that the Element displays there and only there.
-
Hi thanks – is there a way I can make it display after 3 paragraphs down?
Thanks,
Sam -
Hi there,
it requires PHP and a Hook element.
1. Add this PHP to your site:
add_filter( 'the_content', 'db_insert_portable_hook_two', 20 ); function db_insert_portable_hook_two( $content ) { if ( is_single() && ! is_admin() ) { global $post; ob_start(); do_action('inside_post_content'); $inserted_hook = ob_get_clean(); return prefix_insert_after_paragraph( $inserted_hook, 3, $content ); } return $content; } function prefix_insert_after_paragraph( $insertion, $paragraph_id, $content ) { $closing_p = '</p>'; $paragraphs = explode( $closing_p, $content ); foreach ($paragraphs as $index => $paragraph) { if ( trim( $paragraph ) ) { $paragraphs[$index] .= $closing_p; } if ( $paragraph_id == $index + 1 ) { $paragraphs[$index] .= $insertion; } } return implode( '', $paragraphs ); }
2. edit your Block element, change the Hook to
Custom Hook
and in the field add:inside_post_content
-
Hi when I add the php, I am adding it in snippets. Would I be running that snippet “everywhere” Only run in administration area or Only run on site front-end
-
Run it everywhere.
-
thanks.
For element type, I dont see anywhere to put custom hook, nor if I go to make a brand new hook, I don’t see custom hook as an option.
I only see it for Hook Name, but if I put custom hook here, there is nowhere to add inside_post_content
-
There is a custom hook option:
https://app.screencast.com/omCCkCIiMp0ky -
that worked, thanks!
-
You are welcome 🙂
- You must be logged in to reply to this topic.