-
devashishsharma
I’ve recently created a hook for newsletter signups and added it as “generate_before_foot” and location as “Entire site”.
Here is what I want. I want this hook on the homepage somewhere between featured posts (want to add this hook in the page I use as static home page). For posts I’ve a content template element and want to use just after the content.
How can I add the hook at places I want and not at a static fixed place?
-
Fernando
Hi there,
You can add a Portable Hook.
Creating a Portable Hook: https://generate.support/topic/create-a-shortcode-for-an-element/#post-38707
-
devashishsharma
Hi. As you said I added this code to the functions.php file in Appearance > Theme Editor
add_shortcode('portable_hook', function($atts){ ob_start(); $atts = shortcode_atts( array( 'hook_name' => 'no foo' ), $atts, 'portable_hook' ); do_action($atts['hook_name']); return ob_get_clean(); });
Then on the static page for homepage, I created a block and selected shortcode and filled it with:
[portable_hook hook_name="Newsletter Banner"]
Unfortunately nothing happened 🙁
What am I doing wrong?
My hook element name is: “Newsletter Banner” -
Fernando
Make it
[portable_hook hook_name="newsletter_banner"]
instead.Then use the hook Custom –
newsletter_banner
to hook to that Shortcode. -
devashishsharma
Great! It worked. The banner was little messing with the upper element, so I did this:
In shortcode I wrote:
<div class="newsletter_banner"> [portable_hook hook_name="newsletter_banner"] </div>
and in the additional CSS I wrote:
.newsletter_banner { padding: 25px; }
Is it the right way?
Thanks again for the solution.
-
devashishsharma
..or should I just add the shortcode in a container?
-
Fernando
Either way should be fine.
I would personally just add the Shortcode Block inside a GB Container Block for ease of use and management.
-
devashishsharma
Thanks alot! solved.
-
Fernando
You’re welcome!
- You must be logged in to reply to this topic.