Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Maybe i'm wrong but it seems that this question has not been previously solved yet:

There is some iframe inside post content and I want to get rid of that iframe when the rss feeds are generated. To generate rss feeds, I'm showing full post content.

I started looking at strip_tags() but it does pretty much the opposite: strip everything unless the desired tags.

I'm wondering that maybe there is some hook and some wordpress-y form of solving this issue.

I know I should do something like this:

function rss_noiframe($content) {
    global $post;
    // filter out iframe here
    return $content;
    }

add_filter('the_excerpt_rss', 'rss_noiframe');
add_filter('the_content_feed', 'rss_noiframe');

But I'm lost at this point. Any ideas?

On demand by EAmann, here is some example code that isnt modified at all (it still appears in the feed, in fact):

<iframe src="http://somedomain.net/path/to/frame" frameborder="0" scrolling="no" width="500" height="375"></iframe>
share|improve this question
    
What is adding the iframe? Is it a plugin, a shortcode, manually entered in the HTML editor? –  EAMann Jan 16 '13 at 17:50
    
Manually entered :) –  versvs Jan 16 '13 at 17:55

1 Answer 1

up vote 1 down vote accepted

One potential option is to use preg_replace to do a regex match on your content and replace the iframe with empty space.

So this function:

function rss_noiframe($content) {
    $content = preg_replace( '/<iframe(.*)\/iframe>/is', '', $content );

    return $content;
}

add_filter('the_excerpt_rss', 'rss_noiframe');
add_filter('the_content_feed', 'rss_noiframe');

Should automatically convert any instances of <iframe src=...>...</iframe> to a blank.

share|improve this answer
    
thanks, i will try this :) i'm not that skilled with regex and couldnt come up with a solution myself :) –  versvs Jan 16 '13 at 18:53
    
It didnt work, it leaves a completely cleared rss :S –  versvs Jan 16 '13 at 19:46
2  
Can you edit your answer to include some example HTML that has the iframe? All of my tests of the above code worked just fine ... –  EAMann Jan 16 '13 at 19:55
    
i added a sample iframe, thanks again :-) –  versvs Jan 16 '13 at 20:40
    
Ok, sorry, it was my fault... Your code works indeed! I was calling the_content() to do further processing (add thumbnail) and that was overriding your regex. –  versvs Jan 16 '13 at 21:31

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.