• Is there a way to automatically edit out (delete) ads and other links that are embedded in imported RSS feeds?

    We are planning to aggregate several RSS feeds using FeedWordPress or another plugin.

    Several of the RSS sources we are looking to use embed ads in their RSS feeds which show up in the posts created by FeedWordpress.

Viewing 2 replies - 1 through 2 (of 2 total)
  • I am not sure whether you can strip content from a feed while importing it. However you can filter the output. Some time ago i wrote a small plugin for my own use (quick and dirty) to get rid of font and class definitions because they would break the layout of a blog.

    <?php
    /*
    Plugin Name: FWP+: Modify syndicated content
    Plugin URI:
    Description: enable FeedWordPress to modify content in syndicated posts
    Version: 2010.0208
    Author: Michael Weichselgartner
    Author URI: https://www.ntrast.de/
    License: GPL
    */
    
    add_action(
        /*hook=*/ 'the_content',
        /*function=*/ array('FWPRegex', 'my_fwp_regex'),
        /*priority=*/ 10002,
        /*arguments=*/ 1
    );
    
    class FWPRegex {
    
        function my_fwp_regex($content) {
    
        $regex = array ( '/<\/?font[^>]*>/i' => '',
                        '/<\/?strong[^>]*>/i' => '',
                        '/<\/?em[^>]*>/i' => '',
                        '/class=\".[^\"]*\"/i' => ''
        );
    
            if (is_syndicated()) {
    
                foreach ($regex as $key => $value){
                    $content = preg_replace($key, $value, $content);
                }
            }
    
        return $content;
    
        }
    }
    
    ?>

    The array $regex is used to build the “search” and “replace” pairs. In the example above the first array element will serach for html font tags (<font [incl. any attributes like color]></font>) and replace them with nothing (”). The second element does the same with html <strong></strong> tags and the third does is with <em></em> tags. The last element strips out any class definition from the content.

    You can add as many elements to the array as you want to build your custom regex. I just use it to delete tags but you even can replace things with it by entering something in the “replace” part (the second parameter) of a pair (this is the one currently empty in my example).

    Now to strip ads you need to write your own regex. Because this might become a more complex code (not everything can be matched in a single line) you might want to use preg_replace_callback and throw in a custom function.

    To make the example work just save the code into a php file (e.g. fwpregex.php) and put it in a directory (e.g. fwpregex) within your plugins directory from WordPress. Now go to your plugin administartion page and activate the nwely installed regex plugin. From that moment on all syndicated posts from FeedWordPress will be filtered acording to your custom regex rules.

    CAUTION!
    This plugin has not been written for public use and therefore i dont guarantee for anything. You are responsible yourself for writting appropriate regex rules. This plugin filters all posts from all feeds. It is not desined to apply different regex to different feeds.

    I hope i could give you an idea what is possible. Much luck.

    Thread Starter sailpilot

    (@sailpilot)

    thanks. I will play around with your plugin and see if I can get it to do what I need.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘imported RSS feed editing’ is closed to new replies.