Quantcast
Channel: Topic Tag: xml | WordPress.org
Viewing all articles
Browse latest Browse all 3201

jonathanhooverks on "RSS Delete Elements By Class"

$
0
0

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 all articles
Browse latest Browse all 3201

Trending Articles