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.

Place hook at custom places

  • 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?

  • Hi there,

    You can add a Portable Hook.

    Creating a Portable Hook: https://generate.support/topic/create-a-shortcode-for-an-element/#post-38707

  • 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”

  • Make it [portable_hook hook_name="newsletter_banner"] instead.

    Then use the hook Custom – newsletter_banner to hook to that Shortcode.

  • 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.

  • ..or should I just add the shortcode in a container?

  • Either way should be fine.

    I would personally just add the Shortcode Block inside a GB Container Block for ease of use and management.

  • Thanks alot! solved.

  • You’re welcome!

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