Site logo

Archived topic

Can I insert element (hook,block)in post as shortcut?

1 reply · Started by Neronet on December 9, 2022

Viewing posts 1–2 of 2

Can I insert element (hook,block)in post as shortcut?

Hi there,

do you meant a Shortcode ?
If so, add this PHP Snippet to your site:


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();
});

Adding PHP: https://docs.generatepress.com/article/adding-php/

Now think of a name for your hook eg. custom_place_in_content

And you can then add the shortcode for it to your post:

portable_hook hook_name="custom_place_in_content"]

Now in your Element, you can set the Hook to Custom and in the field add your hook name.

This archived topic is closed to new replies.