[Support request] Ad Placement / Custom Hook Code

Home Forums Support [Support request] Ad Placement / Custom Hook Code

Home Forums Support Ad Placement / Custom Hook Code

  • This topic has 9 replies, 3 voices, and was last updated 2 years ago by David.
Viewing 10 posts - 1 through 10 (of 10 total)
  • Author
    Posts
  • #2168189
    Steph

    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?).

    #2168237
    Ying
    Staff
    Customer Support

    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.

    #2168272
    Steph

    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?

    #2168369
    Ying
    Staff
    Customer Support

    You can try play around with the code, change where the </p> is to </h2>.

    #2169605
    Steph

    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?

    #2169635
    David
    Staff
    Customer Support

    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.

    #2169645
    Steph

    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’

    #2169661
    David
    Staff
    Customer Support

    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:

    2022-03-28_13-31-12

    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 🙂

    #2169717
    Steph

    Omg. Thank you so much!

    You are amazing.
    Switching to GeneratePress really was the best decision.

    #2169718
    David
    Staff
    Customer Support

    Awesome – glad to be of help!

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