Archived topic
Ad Placement / Custom Hook Code
9 replies · Started by Steph on March 26, 2022
Hey,
I just join an ad network (SheMedia) and now have to place the ads. I already added some, but I would love to place some inside of my posts.
I assume I have to use a 'generate_inside_container' hook but is there a where to specify where and how often ads are placed?
If possible, I want a maximum of 4 ads per post and only before every second H2 starting with the second one. And then add a little bit of space between the ad and the H2 (around 25 px?).
Hi Steph,
GP doesn't have any hooks in the post content Unfortuanly.
So you would need to manually add the ads to your post content, or you can give this solution a try to create a custom hook after 1st paragraph:
https://generatepress.com/forums/topic/element-after-first-paragraph/#post-1937353
Or you can try find some plugins which automatically place ads for you.
Hey Ying,
thank you. That sure could work if there is a way to adjust the code a bit.
Do you know how I would have to alter that code if I want to create new hooks just before certain H2 headings?
I'd obviously have to create several new hooks (3 or 4) for the different locations, but after that, it should be rather straightforward, right?
You can try play around with the code, change where the </p> is to </h2>.
Adjusting the code only that way does not work. Especially as I want it after different headings... wouldn't that mean I'd also have to specify where?
Hi there,
for that kind of control you will want to use the Ad Inserter plugin:
https://en-gb.wordpress.org/plugins/ad-inserter/
It has all the various content filter functions built in - so placing ads where you want is a breeze. The Free versions should suffice.
Hey David,
I tried that plugin after reading about it in one of the other threads, but it does not have a feature to add ads before headings... I under no circumstances want ads within texts, hence the focus on placing them before headings. Am I missing something?
I might be wrecking my brain with this quest of mine o.O'
If i understand correctly then you can do it with the Ad Insert plugin.
Its a little confusing but you can use the Paragraph Settings
https://adinserter.pro/documentation/paragraph-settings
I was intrigued to see if it worked so did a quick test:
https://www.screencast.com/t/bxqGqMxPQrHR
1. I checked Posts
2. I set Insertion: before paragraph and then %2 which is every 2nd of.
3. Set the Paragraph with Tags to h2
And that worked :)
Omg. Thank you so much!
You are amazing.
Switching to GeneratePress really was the best decision.
Awesome - glad to be of help!