Site logo

Archived topic

Add content after each post

15 replies · Started by WebbPlatsen on August 11, 2022

Viewing posts 1–15 of 16

I want to show ads after each post in the archive view.
Looking for which hook to use, but can't find it.

I don't want to use Elements since there will be some custom code.

Wanted this;
[POST #1]
[AD]
[POST #2]
[AD]
[POST #3]
[AD]
[POST #n]
[AD]

Hi there,

you can use the generate_after_do_template_part hook.

See here:

https://github.com/tomusborne/generatepress/blob/8bff7e067bb4df92ce1711fddb843585d4d18e71/inc/theme-functions.php#L594

It comes after the get_template_part function that is used to display the content template.

Thanks!
I have activated "Use infinite scroll" and content will be added on first posts, but not when infinite scroll kicks in.

The infinite scroll checks the next page and looks for any article HTML Elements to load.
So you need to make sure your adverts are inside an article eg.

<article>
 <!-- your advert -->
</article>

I have a function which hook my ads into "generate_after_do_template_part".

Can i see your function ?


function wps_just_tezt() {

    if (is_archive()) {
      echo '<pre>HELLO WORLD</pre>';
    }
}
add_action( 'generate_after_do_template_part', 'wps_just_tezt');

Sp here:

echo '<pre>HELLO WORLD</pre>';

you would:

echo '<article><pre>HELLO WORLD</pre></article>';

No difference.

Works for my first 5 posts.
I have "Blog pages show at most" set to 5 in Settings.

Can you share a link to the site where i can see this ? Then i can check the markup

Yes I will.

What if we hooked the content into the post itself ? So instead of it being between posts it was hooked into the foot of each post ?

Yes. That's fine too.

Try the generate_after_content hook.

Looks good now. Thanks :)

Would be great if there was a hook for archive.
Now I need to use is_archive function.

Using <article> is not necessary.

This archived topic is closed to new replies.