• Skip to main content
  • Skip to forum navigation

StudioPress

  • Shop for Themes
  • My StudioPress

Forum navigation

  • Home
  • General Genesis Discussions
  • StudioPress Themes
  • Genesis Blocks
    • Genesis Blocks
    • Genesis Custom Blocks
  • Retired Themes
  • FAQs
  • Forum Rules
  • Internationalization and Translations
  • Forum Bugs and Suggestions
  • Forum Log In

Are You Using The WordPress Block Editor?

Genesis now offers plugins that help you build better sites faster with the WordPress block editor (Gutenberg). Try the feature-rich free versions of each plugin for yourself!

Genesis Blocks Genesis Custom Blocks

Add Adsense to the final Content Post

Welcome!

These forums are for general discussion on WordPress and Genesis. Official support for StudioPress themes is offered exclusively at My StudioPress. Responses in this forum are not guaranteed. Please note that this forum will require a new username, separate from the one used for My.StudioPress.

Log In
Register Lost Password

Community Forums › Forums › Archived Forums › Design Tips and Tricks › Add Adsense to the final Content Post

This topic is: not resolved

Tagged: adsense

  • This topic has 9 replies, 2 voices, and was last updated 13 years, 3 months ago by Brad Dalton.
Viewing 10 posts - 1 through 10 (of 10 total)
  • Author
    Posts
  • April 17, 2013 at 2:35 am #35909
    Manuel
    Member

    Hi,

     

    I now is very simple but i can´t find the  correct code, I  want to add adsense  to the final of my post  but I add some pluggins and bars  and I need to add it before one bar (sharethis pluggin), also I need it to add it in the content area,

     

    I already try this code:

    add_action('genesis_after_post_content', 'adsense_after_posts');
    function adsense_after_posts() {
    if (is_single() )
        echo '<div class="adsense-style">Adsense goes here</div>';
    }  

    Thanks

    http://
    April 17, 2013 at 2:54 am #35910
    Brad Dalton
    Participant

    Can you link to your site please.


    Tutorials for StudioPress Themes.

    April 17, 2013 at 11:20 am #35974
    Manuel
    Member

    Hi. Brad:

    Here is the link

     

    http://comodefinirabdominales.com/como-reducir-grasa-en-el-abdomen-sin-abandonar-la-rutina/

    I want to add it before the share bar.

     

    Thanks!

    April 17, 2013 at 11:32 am #35976
    Manuel
    Member

    Also I need to add a Adsense banner before the shareThis pluggin but in the home page.

     

    http://comodefinirabdominales.com/

     

    Thanks!

    April 17, 2013 at 5:32 pm #36025
    Manuel
    Member

    sorry, Also If you can help me with another issue, i need to add Adsense banner before the shareThis pluggin but in the home page, I get a little confused when I try to add the adsense.

    Here is the link of my website:

     

    http://comodefinirabdominales.com/

     

    Thanks

    Best Rewards!!

    April 17, 2013 at 6:08 pm #36028
    Brad Dalton
    Participant

    Try this:

    https://gist.github.com/5408822.git


    Tutorials for StudioPress Themes.

    April 18, 2013 at 2:17 am #36094
    Manuel
    Member

    Thanks Brad it work great.

    I don't want to bother, but i get a little frustrated,   I tried  this  code, it works, but if the   post have photos or another element like a video it will avoid those elemnts, and the banner will be in another part

    <code>

    add_filter( 'the_content', 'wpsites_adsense_middle_content' );
    function wpsites_adsense_middle_content( $content ) {
    if( !is_single() )
    return $content;

    $paragraphAfter = count ( $content ); //Enter paragraph number
    $content = explode ( "</p>", $content );
    $new_content = '';
    for ( $i = 0; $i <= count ( $content ); $i ++ ) {
    if ( $i == $paragraphAfter ) {
    $new_content .= '<div style="width: 300px; height: 250px; padding: -5px -5px 0px 0; margin-right: 0;align=Top;display:inline-table;border:none;position:relative;float:left">';
    $new_content .= '<script type="text/javascript">Script Adsense</script>';
    $new_content .= '<center><strong>Enlace Patrocinado</strong></center></div>';
    }
    $new_content .= $content[$i] . "</p>";
    }
    return $new_content;
    }

    </code>

    Also i now that always  in the content I  have  the <p></p> tag element,  the last  <p> is the ShareThis pluggin, I want to add it before the last <p> tag,I know i can count the elements of a class, but I cant implemented, What could be the best for to count the elements tags in a class, or is a function of theme than give me that info?

    http://comodefinirabdominales.com/como-reducir-grasa-en-el-abdomen-sin-abandonar-la-rutina/

     

    April 18, 2013 at 2:30 am #36099
    Brad Dalton
    Participant

    Thats my code also. Where did you get it?

    You can't use that code for what you want because its developed to display the Adense after a specific amount of paragraphs which will be different on different posts.

    You'll find Adsense converts better when its above the fold and typically before the content which is where you might want to display your Adsense.

    I see you already add an image after posts so you have to change the hook or add a thrid parameter for the priority.

    What code are you using for displaying the image after single posts?


    Tutorials for StudioPress Themes.

    April 18, 2013 at 1:17 pm #36203
    Manuel
    Member

    I get it here , in the forum, you posted this code in another thread,I read past  posts to try to solve this problem,, I use this code:

    <code>

    add_filter( 'the_content', 'wpsites_adsense_middle_content' );
    function wpsites_adsense_middle_content( $content ) {
    if( !is_single() )
    return $content;

    $paragraphAfter = 0; //Enter paragraph number
    $content = explode ( "</p>", $content );
    $new_content = '';
    for ( $i = 0; $i < count ( $content ); $i ++ ) {
    if ( $i == $paragraphAfter ) {
    $new_content .= '<div style="width: 300px; height: 250px; padding: -5px -5px 0px 0; margin-right: 0;align=Top;display:inline-table;border:none;position:relative;float:left">';
    $new_content .= 'Adsense Code'
    $new_content .= '<center><strong>Enlace Patrocinado</strong></center></div>';
    }
    $new_content .= $content[$i] . "</p>";
    }
    return $new_content;
    }

    </code>

    I aslo  tied usging wp insert, but  I cant get   the position exactly where i want it, I  want to Add a 300x250 banner between the image and the  sharethis Bar, that the reason i want to add it always before the  last<p> tag.

     

    Thanks !!

     

    April 18, 2013 at 7:17 pm #36255
    Brad Dalton
    Participant

    O.k I Understand where you want it displayed but don't know which hook you are currently using for the after post image.

    I think you should try and add another widget area before the image which looks like its using the same hook.

    Which hook is it using Manual?

    Or you could use another hook or add a priority to another function using the same hook or use 2 text widgets in the same widget area.


    Tutorials for StudioPress Themes.

  • Author
    Posts
Viewing 10 posts - 1 through 10 (of 10 total)
  • The forum ‘Design Tips and Tricks’ is closed to new topics and replies.

CTA

Ready to get started? Create a site or shop for themes.

Create a site with WP EngineShop for Themes

Footer

StudioPress

© 2026 WPEngine, Inc.

Products
  • Create a Site with WP Engine
  • Shop for Themes
  • Theme Features
  • Get Started
  • Showcase
Company
  • Brand Assets
  • Terms of Service
  • Accptable Usse Policy
  • Privacy Policy
  • Refund Policy
  • Contact Us
Community
  • Find Developers
  • Forums
  • Facebook Group
  • #GenesisWP
  • Showcase
Resources
  • StudioPress Blog
  • Help & Documentation
  • FAQs
  • Code Snippets
  • Affiliates
Connect
  • StudioPress Live
  • StudioPress FM
  • Facebook
  • Twitter
  • Dribbble