- This topic has 28 replies, 5 voices, and was last updated 3 years, 2 months ago by
Fernando.
-
AuthorPosts
-
November 18, 2022 at 3:34 am #2421175
Rajeev
i am just want to know how can i insert a ads after 5th post of homepage ?
November 18, 2022 at 11:32 am #2422013Ying
StaffCustomer SupportHi there,
Is your homepage the blog page?
November 18, 2022 at 9:25 pm #2422442Rajeev
Yeah
November 19, 2022 at 5:23 am #2422761David
StaffCustomer SupportHi 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 toFront Page.In the hook text area, add you advert code.
November 19, 2022 at 10:42 am #2423231Rajeev
ok thanks
and what if i’m want to add ads to after 5th post then 10th post and 15th post simounteneously ?November 19, 2022 at 11:41 am #2423266Rajeev
and i want to know which file i can edit for this code without wp login (mean from cpanel) ?
November 19, 2022 at 1:55 pm #2423367Ying
StaffCustomer Supportand 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/November 20, 2022 at 2:37 am #2423752Rajeev
i can’t understand with duplicate and convert the code ?
am trying but its showing errortell me step by step plz
November 20, 2022 at 5:02 am #2423887David
StaffCustomer SupportIf 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.
November 22, 2022 at 2:16 am #2426824Rajeev
thanks
November 22, 2022 at 6:27 am #2427143David
StaffCustomer SupportYou’re welcome
November 22, 2022 at 6:47 am #2427181jmarc
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
JMArcNovember 22, 2022 at 8:25 am #2427534David
StaffCustomer SupportHi there,
that code doesn’t define a user logged in status.
Are you using any cache plugins ? Perhaps a page cache needs clearing.November 22, 2022 at 11:48 am #2427837jmarc
Hello David,
It’s ok now 🙂
thank you
JMNovember 23, 2022 at 2:44 am #2428650David
StaffCustomer SupportYou’re welcome 🙂
-
AuthorPosts
- You must be logged in to reply to this topic.