Filter: Strip Any Tags from the Excerpts

Some RSS feeds’ excerpts include hyperlinks or other HTML tags that you might not necessarily want to appear on your site.

For example, you might not want to remove the linked text itself, but you don't want the link. Or you may have excerpts that contain certain words in bold or italics, but you don't want them to be so on your site.

For this purpose, you can use the following code snippet.

add_filter( 'wprss_populate_post_data', 'my_strip_tags', 1000, 2 );
function my_strip_tags( $args, $item ) {
  $args['post_content'] = strip_tags( $args['post_content'], '<b><i><p><span><img>' );
  return $args;
}
NOTE: The part that says   <b><i><p><span><img> specifies which HTML tags are allowed. So the function will strip all tags that aren’t <b>, <i>, <p>, <span> and <img> tags. You can add or remove any of them as needed.

How do I add this to my site?

Follow the step-by-step instructions below to add this filter to your WordPress site.

  1. Copy the code you need from above.
  2. Go to your WordPress site's dashboard.
  3. Go to Plugins > Add New.
  4. Search for Code Snippets, then install and activate the plugin.
  5. Once installed and activated, go to Snippets in your dashboard menu.
  6. Click on Add New.
  7. Add a Title, which could be the title of this article.
  8. Paste the code you copied in step 1 to the Code section.
  9. Add a Description or Tags if you wish to do so. It is not required.
  10. Click on Save Changes and Activate to save the filter and activate it.
    1. Or click on Save Changes to save the filter and activate it later.
  11. Your action or filter is now stored and active on your site.

Still need help? Contact Us Contact Us