Site logo

Archived topic

I need to a a hook on singlepost to add paragraph block above cat-links

3 replies · Started by Justin on November 29, 2022

Viewing posts 1–4 of 4

Hello,

Is there a way to use hooks to insert a paragraph between the bottom of singlepost text and the top of the cat-links? See the area highlighted in green.

can a block be added in the green area?

Thank you,

Justin

Hi Justin,

There's a way. One Approach is to add this Snippet:

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

add_filter( 'the_content', 'insert_featured_image', 20 );
function insert_featured_image( $content ) {
    global $post;
    $inserted_hook = do_shortcode('[portable_hook hook_name="after_entire_content"]');
	
    if ( is_single() && ! is_admin() ) {
         return $content . $inserted_hook;
    }
    return $content;
}

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

This code allows you to use Custom Hook - after_entire_content. Example: https://share.getcloudapp.com/jkuOqdlN

Fernando,

Thanks so much for the quick reply. I noticed that the Adding PHP doc you linked to was last updated in 2018. Is using the Code Snippets plugin still the preferred way to add PHP snippets to a GP website? Is there a new way to accomplish the same thing using Elements? Just thought I check first.

Thanks again for your help.

Is using the Code Snippets plugin still the preferred way to add PHP snippets to a GP website?

Yes :)

This archived topic is closed to new replies.