WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Filter to add content to post, but not feed (4 posts)

  1. ruudkok
    Member
    Posted 3 years ago #

    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?

  2. Joseph
    Member
    Posted 3 years ago #

    Add a condition to it?

    if (!is_feed())
    	$content .= 'Add this line';
  3. Tibor Paulsch
    Member
    Posted 3 years ago #

    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');
  4. ruudkok
    Member
    Posted 3 years ago #

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

Topic Closed

This topic has been closed to new replies.

About this Topic