Support » Developing with WordPress » Manipulating a feed

  • Resolved joetaxpayer


    I am loading an rss feed into a sidebar box, it works fine, except – every post listed starts with the 12 character author name. I’d like to strip that out, as the name will appear at the top of the widget/box, and Feed will link back. Any way to filter out X characters?

Viewing 6 replies - 1 through 6 (of 6 total)
  • Moderator Ipstenu (Mika Epstein)


    🏳️‍🌈 Halfelf Rogue & Plugin Review Team Rep

    Assuming you’re using the RSS widget, you can just tell it not to include the poster’s name.

    I’m not using the widget, doing it the longer way.
    I had some widget issues, some showing some not, and decided to avoid completely.

    if you are parsing the feed yourself then the following code can be used to parse the feeds. In the endElement function you can do anything you want. This code I’m using in a widget I wrote to parse RSS feeds.:

    function startElement($xp,$name,$attributes) {
    				global $item,$currentElement;  $currentElement = $name;
    				//the other functions will always know which element we're parsing
    				if ($currentElement == 'ITEM') {
    					//by default PHP converts everything to uppercase
    					$item = true;
    					// We're only interested in the contents of the item element.
    					////This flag keeps track of where we are
    			function endElement($xp,$name) {
    				global $item,$currentElement,$title,$description,$link,$rssCount;
    				if ($name == 'ITEM' && $rssCount < $this->maxRssEntries) {
    					// If we're at the end of the item element, display
    					// the data, and reset the globals
    					echo "<div class='custom-feed'>";
    					echo "<div class='custom-feed-title'><a href='" . $link . "'>$title</a></div>";
    					echo "<div class='custom-feed-desc'>$description</div>";
    					echo "</div>";
    					$rssCount += 1;
    					$title = '';
    					$description = '';
    					$link = '';
    					$item = false;
    				}elseif($name == 'ITEM'){
    					$title = '';
    					$description = '';
    					$link = '';
    					$item = false;
    			function characterDataHandler($xp,$data) {
    				global $item,$currentElement,$title,$description,$link;
    				if ($item) {
    				//Only add to the globals if we're inside an item element.
    					switch($currentElement) {
    					case "TITLE":
    						$title .= $data;
    						// We use .= because this function may be called multiple
    						// times for one element.
    					case "DESCRIPTION":
    					case "LINK":
    			function readFeeds($feed) {
    				global $rssCount;
    			  $fh = fopen($feed,'r');
    				// open file for reading
    			  $xp = xml_parser_create();
    				// Create an XML parser resource
    			  xml_set_element_handler($xp, array($this,"startElement"), array($this,"endElement"));
    				// defines which functions to call when element started/ended
    			  xml_set_character_data_handler($xp, array($this,"characterDataHandler"));
    				while ($data = fread($fh, 4096)) {
    					if($rssCount < $this->maxRssEntries){
    						if (!xml_parse($xp,$data)) {
    							return 'Error in the feed';

    Sorry in advance if I misunderstood your question.

    [signature moderated Please read the Forum Rules]

    I appreciate the reply. I may be in over my head with this.
    I am looking at my twitter feed;

    I put this inside a sidebar widget;
    // <?php eat_rss_feed(“”,””,”


    • %title%
    • “,3); ?>

      And I get;
      JoeTaxpayerBlog: RT @taxgirl: Please no more Christmas music in stores and commercials. It’s September. >> Costco skipped right to Xmas stuff, too.

      I’d just like to cut off the first 16 characters, my name would be in the box title, doesn’t need to be in every feed line. I hope that’s clear. And hoping the answer is a magic line or two to add.
      Again, thanks.

    Food Blogger


    Have you tried using Yahoo Pipes to edit an RSS feed and manipulate it to what ever you want? ie: strip stuff, prepend stuff etc? You may want to give that a try.

    biglist –
    Absolutely amazing. For whatever reason, it gave me an error trying to load the new feed last night, but it burped through and looks perfect now.
    I am far from the 200/hr visitor max that the pipes seem to have, so for now, this may be the right solution.
    I’m surprised that RSS feeds aren’t more easily clipped, all I wanted was to remove first N characters.
    Anyway, thanks again.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Manipulating a feed’ is closed to new replies.