WordPress.org

Support

Support » Plugins and Hacks » Hacks » [Resolved] Filter to add content to post, but not feed

[Resolved] Filter to add content to post, but not feed

  • Inspired on the WordCamp NL last weekend I started playing around writing a little plugin of my own.

    I use this code to add a bit of text to the bottom of each post:

    function add_some_tekst_of_mine($content)
    {
    $content .= ‘Add this line’;
    return $content;
    }

    add_filter(‘the_content’,’add_some_tekst_of_mine’);

    However, I ran into a little problem, since the added line also returns in the RSS feed.
    Since I don’t want that to happen, how can I make sure that the function will not be applied to the feed and only to the postings on the website?

Viewing 3 replies - 1 through 3 (of 3 total)
  • Add a condition to it?

    if (!is_feed())
    	$content .= 'Add this line';

    It seems to me, that in this case you don’t need an argument for the function. So unless you plan to do more complicated things, I guess you could accomplish the same this way:

    function add_some_tekst_of_mine() {
     if (!is_feed()) {
      echo 'Add this line';
      }
    }
    add_filter('the_content','add_some_tekst_of_mine');

    Thank you! The (!is_feed()) conditions seems to do the job.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘[Resolved] Filter to add content to post, but not feed’ is closed to new replies.