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