How to add code to end of every post

Community Forums Forums Design Tips and Tricks How to add code to end of every post

This topic is: not resolved

This topic contains 5 replies, has 3 voices, and was last updated by  Pinky 1 year, 1 month ago.

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #27200

    peps2004
    Participant
    Post count: 8

    I’m wanting to automatically add AdSense code to the end of each post in the future without having to manually add it to each post.

    I’ve tried a few of the simple hook options that I thought might work, but they didn’t place it in the correct place. I want it to display within the post content above the category and tag listings for that post – is one of the hooks set up for that?

    The site is http://scavenger-hunt.org/ if that helps.

    #27336

    Pinky
    Participant
    Post count: 93

    I’ve just done a quick search for a plugin to do that, and there seem to be a few…

    Take a look at this G search:

    https://www.google.com.au/search?q=plugin+add+content+toend+of+post

    OR

    You could use the code similar to adding a signature image to the end of posts

    
    // Add Signature Image after posts
    add_action('genesis_after_post_content', 'custom_include_signature', 1);
    function custom_include_signature() {
     { ?>
     <img src="http://yoursite.com/yourimage.png" alt="your image name here" />
    <?php }}
    
    

     

    I also find this page is really valuable and has helped me work things out : http://genesistutorials.com/visual-hook-guide/

     

    Hopefully that helps a little


    cheers

    Pinky

    #27341

    braddalton
    Participant
    Post count: 7473

    Install the Genesis Simple Hooks plugin and paste in your Adsense code in any genesis_hook location.

    <?php if (is_single() ) { ?>
    <p>Adsense-Code-Goes-Here</p>
    <?php } ?>
    

    Change the conditional tag if needed.

    Or you can use a custom function:

    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>';
    }	
    

    WordPress Developer & Consultant
    Brad Dalton400+ StudioPress Tutorials & 1200+ Code snippets

    #27360

    peps2004
    Participant
    Post count: 8

    Hi guys,

    Thanks for that – I hadn’t seen that visual hooks guide before. I tried out the genesis_post_content and that seems to be just what I need. I’d assumed by the title that it would place the code at the beginning of the post but it adds it to the end of the post.

    #27363

    braddalton
    Participant
    Post count: 7473

    You may need to reposition the post meta if you want your ads displayed before those links.


    WordPress Developer & Consultant
    Brad Dalton400+ StudioPress Tutorials & 1200+ Code snippets

    #27715

    Pinky
    Participant
    Post count: 93

    Glad it was helpful – I have that page and a few others in my bookmarks tab for quick reference


    cheers

    Pinky

Viewing 6 posts - 1 through 6 (of 6 total)

You must be logged in to reply to this topic.