• jonathanhooverks

    (@jonathanhooverks)


    I want to use RSS from wordpress to drive my MailChimp campaigns, but I have several elements on the page that I don’t want in my rss (like a gravity form, an image or two that doesn’t apply to my email viewers, etc.).

    I can use CSS on the mail chimp side to {display:none} the elements with the .hidefromrss class, but because Gmail won’t tolerate the display css property, I’m out of luck.

    I’d like to obliterate every item with class .hidefromrss from my rss feeds. I don’t know which is the best way to go here… should I try to use a php reg_replace statement? Or should I try to use a javascript call using the DOM? Would it be better to use jquery? If so to any of these, could you give an example of how this would be done? I’m open to any potential solution. I thought this would be an easy thing to do. Man, was I ever wrong : )

Viewing 1 replies (of 1 total)
  • Thread Starter jonathanhooverks

    (@jonathanhooverks)

    OK, so in case anyone else ends up having the same challenge I did, here’s how I solved it. I wrote a new plugin, and included the following code:

    function hidefromrss( $content )
    	{
    
    		// in case we want to add to earlier versions
    		if (  is_feed() )
    		{
    			$dom = new DOMDocument;
    			$dom->loadHTML(mb_convert_encoding($content, 'HTML-ENTITIES', 'UTF-8'));
    			$xpath = new DOMXPath( $dom );
    			$pDivs = $xpath->query(".//div[@class='hidefromrss']");
    
    			foreach ( $pDivs as $div ) {
      			$div->parentNode->removeChild( $div );
    			} 
    
    			$content = preg_replace( "/.*<body>(.*)<\/body>.*/s", "$1", $dom->saveHTML() );
    
    		}
    
    		return $content;
    	}
    
    	add_filter("the_content","hidefromrss");
Viewing 1 replies (of 1 total)

The topic ‘RSS Delete Elements By Class’ is closed to new replies.