Display Ads After Specific Paragraph on Single Posts

Displaying different types of advertisements within the content area of your blog posts can be achieved using several methods.

According to the experts, placing the ads on the top left hand corner of your posts or after the first paragraph converts the best.

This is not something you may want to do because the ads can be far too random and may imply endorsement of products and services which you don’t use or recommend.

However, if you have bills to pay then Adsense or other types of banner and text ads can convert well when displayed within content that is related to the banner or text advertisement.

Theme Specific Locations

Genesis theme framework users can easily display ads using genesis hooks in a custom function or using the Genesis Simple Hooks plugin.

Before and after posts content hooks are the most popular but what if you want your ads to automatically display after a specific paragraph?

You’ll need a custom function which you’ll find in the code snippet below or on Github.

Display Ads After Specific Paragraph

Note: This code may need modifying depending on exactly where you want to display your ads after a paragraph in respect of the margins and padding.

Related Tutorials


Comments

19 responses to “Display Ads After Specific Paragraph on Single Posts”

  1. Santiago Avatar

    Just what i needed!!! Do you know how to put ads after the 2 first posts in the home? I see tutorials about this, but all of them puts ads EVERY 2 or 3 posts, i mean, repeteadly… Thanks and sorry for my bad english…

    1. Brad Dalton Avatar
      Brad Dalton

      Yes but answers for members only

  2. Lisette Avatar

    Hi Brad! This is awesome!

    Is there a way we can modify this so that it only appears on wp_mobile? I currently have an ad appearing only in mobile before the content area using Genesis Simple hooks, but I would love to use this method in functions.php instead.

    Any ideas? Thanks!

    1. Brad Dalton Avatar
      Brad Dalton

      Hello Lisette

      You could try replacing the conditional tag after the function with a line like this:

      Source code https://core.trac.wordpress.org/browser/tags/3.6/wp-includes/vars.php#L106

      1. Lisette Avatar

        That’s what I was thinking, but I didn’t want to take my site down due to an error in writing the conditional.

        I tried that verbatim on a test site and it took down the site. I replaced && with && and it was up again, although I’m not sure that was the reason I had an error.

        In any case, you’ve solved an issue I’ve been wrestling with for two days. Thanks so much, Brad!

        1. Brad Dalton Avatar
          Brad Dalton

          I think you understand that was caused by the embed not displaying correctly right?

          I’ve updated the code now.

  3. Sandeep Avatar

    hey Brad,

    Thanks for this awesome trick. I already started using this on my website. If possible can you tell me a way so that I can have two 300by300 adsense ad blocks side by side.

    my website is thegeekdiary.com

    Thanks again.

  4. Shashank Bhattarai Avatar
    Shashank Bhattarai

    Hello, After post ads implementation is not working in my website. I need to fix it . If you can show me the correct codes.I am using latest version of genesis framework. I tried to implement adding these piece of code in function.php by creating widgers. Check out please ..if there is any error in the code.

    [code]
    add_action( ‘genesis_after_post_content’, ‘child_after_post_content_ad’, 9 );
    function child_after_post_content_ad() {
    if ( is_single() && is_active_sidebar( ‘after-post-content-ad’ ) ) {
    echo ”;
    dynamic_sidebar( ‘after-post-content-ad’ );
    echo ”;
    }
    }
    [/code]

    1. Brad Dalton Avatar
      Brad Dalton

      This is the correct code to use for sites running HTML 5 child themes:
      [code]
      add_action( ‘genesis_entry_footer’, ‘after_entry_widget’, 1 );
      function after_entry_widget() {

      if ( ! is_singular( ‘post’ ) )
      return;

      genesis_widget_area( ‘after-entry’, array(
      ‘before’ => ‘

      ‘,
      ‘after’ => ‘

      ‘,
      ) );
      }
      [/code]

      Change the genesis_entry_footer hook to genesis_after_post_content if using the old XHTML markup in your child theme.

  5. Hi Brad,

    This is what I have been looking for and I must say “Thank You” for providing this code. However, could you help me with a modification for how to make the ads appear on single posts but after 2 different paragraphs e.g: after paragraph 2 and 4 of single posts? I’ll be happy to receive a mail from you if you don’t want to share it here.

    Many thanks

  6. Hi and thanks for this insight. I am on the verge of buying genesis with child theme but need to know if genesis will allow for the placement of the 728 x 90 text ad inside the content?

    This is a good size for what I’m looking to do with adsense but having a hard time finding the specific answer.

    Keep up the good work!

    1. Brad Dalton Avatar
      Brad Dalton

      Yes. You can hook it in conditionally or create a widget area for the banner.

      The banner will display according to the content width.

      1. I appreciate your response. Thank you! If you are an affiliate of Genesis, I would be happy to go through your link. Let me know, as you are the one and only that has responded.

        Cheers from across the pond:)

        1. Brad Dalton Avatar
          Brad Dalton

          Yes, there’s a link in my footer.

          Thanks Sandra.

  7. This is awesome, thanks so much! How can I align right (I tried div align=”right” to no avail) and have the text wrap around the ad block?

    1. Brad Dalton Avatar
      Brad Dalton

      Hi Eric

      You could align it in your editor first and then copy the HTML from your text editor into the code.

      Otherwise you will need to add a new class and use it in a new rule in your style sheet.

      1. Thanks for the quick response. I kept doing some digging in the code when align: center didn’t work. I changed the word align to float and it worked like a charm. Thanks for sharing this great code!

        1. Brad Dalton Avatar
          Brad Dalton

          No worries Eric.

          I was thinking about making this into a widget so its more flexible.

Leave a Reply

Join 5000+ Followers

Get The Latest Free & Premium Tutorials Delivered The Second They’re Published.