Site logo

[Resolved] how can i insert a ads after 5th post on homepage

Home Forums Support [Resolved] how can i insert a ads after 5th post on homepage

Home Forums Support how can i insert a ads after 5th post on homepage

Viewing 15 posts - 1 through 15 (of 29 total)
  • Author
    Posts
  • #2421175
    Rajeev

    i am just want to know how can i insert a ads after 5th post of homepage ?

    #2422013
    Ying
    Staff
    Customer Support

    Hi there,

    Is your homepage the blog page?

    #2422442
    Rajeev

    Yeah

    #2422761
    David
    Staff
    Customer Support

    Hi there,

    you can add this PHP Snippet to your site:

    
    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 == 5 ) {
            echo do_shortcode('[hooky_shortcode]');
        } 
    });

    Then go to Appearance > Elements and create a new Hook Element.
    Set the Hook to Custom and in the field provided add: db_inside_post_loop
    Set the Display rules to Front Page.

    In the hook text area, add you advert code.

    #2423231
    Rajeev

    ok thanks
    and what if i’m want to add ads to after 5th post then 10th post and 15th post simounteneously ?

    #2423266
    Rajeev

    and i want to know which file i can edit for this code without wp login (mean from cpanel) ?

    #2423367
    Ying
    Staff
    Customer Support

    and what if i’m want to add ads to after 5th post then 10th post and 15th post simounteneously ?

    You need to duplicate the code and convert it, so it creates a hook for 10th post and another hook for 15th post.

    and i want to know which file i can edit for this code without wp login (mean from cpanel) ?

    Not sure what you mean. But if you want to add PHP functions to your site, you can use one of the methods introduced in the article:
    Adding PHP: https://docs.generatepress.com/article/adding-php/

    #2423752
    Rajeev

    i can’t understand with duplicate and convert the code ?
    am trying but its showing error

    tell me step by step plz

    #2423887
    David
    Staff
    Customer Support

    If you want to handle multiple adverts in the loop, then the best option is to use the Ad Inserter plugin.

    https://wordpress.org/plugins/ad-inserter/

    Its code is built for this kind of thing, theres no benefit in trying to do it with code especially if you’re not that confident with adding PHP to your site.

    #2426824
    Rajeev

    thanks

    #2427143
    David
    Staff
    Customer Support

    You’re welcome

    #2427181
    jmarc

    Hello David

    I also try this code and it works only when I’m loggued as an admin ! Users cannot see it ! Why ?:(

    Thank you
    JMArc

    #2427534
    David
    Staff
    Customer Support

    Hi there,

    that code doesn’t define a user logged in status.
    Are you using any cache plugins ? Perhaps a page cache needs clearing.

    #2427837
    jmarc

    Hello David,
    It’s ok now 🙂
    thank you
    JM

    #2428650
    David
    Staff
    Customer Support

    You’re welcome 🙂

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