Add HTML To The End of Every WordPress Post

Great for signup forms or affiliate links

I don’t place the DigitalOcean affiliate link manually at the end of each post. That’s because it’s super easy to do with add_filter('the_content').

Add The Message, With or Without HTML

function add_post_bottom_content($content){

    $html = '<span class="post-footer-message"><a href="http://oursponsor.com" target="_blank">Thanks to our sponsor for the generous donation!</a></span>';

    if( !is_page( ) && isset($html) ) {

        return $content . $html;

    } else {

        return $content;

    }

}

add_filter('the_content', 'add_post_bottom_content');

To disable the content, just empty the $html variable .

$html='';

The anchor tag is wrapped in a span with a class of post-footer-message. You’ll want to style your message with that, rename the classes if you want, just stay consistent with the naming.

Some basic styling, with no underline on hover:

span.do_link a:hover {
  font-style:none;
}

As long as you have some basic CSS knowledge, you’ll be able to apply all the styling you need. Just remember to add your CSS to your child theme’s style.css file, or load up the custom CSS file.

The code in this post can go in your theme’s functions.php file or in your WordPress functionality plugin.

  • Kunal

    I tried your method. It works, but it also adds the subscription box after the preview of each post on my front page. It would be great if you could explain how to get rid of that. Thanks.