Site logo

[Support request] I need to a a hook on singlepost to add paragraph block above cat-links

Home Forums Support [Support request] I need to a a hook on singlepost to add paragraph block above cat-links

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

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #2440509
    Justin

    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

    #2440553
    Fernando
    Customer Support

    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

    #2441843
    Justin

    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.

    #2441871
    Leo
    Staff
    Customer Support

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

    Yes 🙂

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