Site logo

[Support request] Add Hook In-between Second & Third Post Blog Archives

Home Forums Support [Support request] Add Hook In-between Second & Third Post Blog Archives

Home Forums Support Add Hook In-between Second & Third Post Blog Archives

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #2415608
    Gareth

    Hello,

    I want to add a hook on my blog archives between the second and third post.

    I’ve been reading the forum and have added the following code below.

    add_action('generate_after_do_template_part',function(){
        global $loop_counter;
        $loop_counter++;
        if ( $loop_counter == 2 ) {
            echo do_shortcode('[name_of_shortcode]');
        } 
    });

    I’m having problems turning the hook into shortcode if that makes sense. I’ve manages to get as far is pulling in “name of shortcode” to the desired spot (see image). But cant pull my dynamic block through.

    Any advice would be great!

    Many Thanks,
    Gaz

    hook

    #2415609
    Gareth
    #2415737
    Fernando
    Customer Support

    Hi Gareth,

    Try this PHP snippet instead:

    function db_hook_inside_shortcode($atts, $content = null) {
          ob_start();
          do_action('db_inside_post_loop');
          return ob_get_clean();
    }
    add_shortcode('hooky_shortcode', 'db_hook_inside_shortcode');
    
    add_action('generate_after_do_template_part',function(){
        global $loop_counter;
        $loop_counter++;
        if ( $loop_counter == 2 ) {
            echo do_shortcode('[hooky_shortcode]');
        } 
    });

    With this, you’ll have a custom action hook called db_inside_post_loop after the 2nd Post in your Archives.

    Then, you can use a Block or Hook Element to inject stuff in that specific location.

    Just set the Hook name to Custom Hookdb_inside_post_loop.

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