Monday 3 October 2011

How to add custom content to each post automatically?




Many bloggers will have a habit to write custom content after each post. Like “We welcome your suggestions on this blog “ Or something like ask readers to subscribe their RSS feed “If you like this post subscribe to our rss feed”.

We can hard code this content after the post content or we can add it every time when we write a new post. Adding this content every time, when we write a new article is not the right choice.

To automate this one add the following code to your theme functions.php i.e

function addFootNote($content) {
        if(is_feed() || is_single()) {
                $content.= "<div class='subscribes'>";
                $content.= "<h4>like this article?</h4>";
                $content.= "<p>Subscribe to our  <a href='http://feeds2.feedburner.com/wordpressnotes>RSS feed</a> </p>";
                $content.= "</div>";
        }

        return $content;
}

3 comments:

  1. Is this function to be hooked to 'the_content' hook? Or else where should i make a call to this function?

    ReplyDelete
  2. ya hisham this function is hooked to the_content only.you just copy this code in functions.php no need to call this again.keep watch my blog.thanks for the comment

    ReplyDelete
  3. I mean shouldn't we do add_action('the_content','addFootNote'); in functions.php?

    ReplyDelete