Skip to content

How to keep HTML in feed items content? ​

📝 Note: The code snippet below applies only to feeds displayed with the Feedzy widget or shortcode. To keep HTML in imported posts, see Keep HTML in imported posts.

Some feeds have HTML tags for the content or other elements. If you want to keep them, then this tutorial will help you.

1. Copy the following code snippet.

2. Paste it into the child theme's functions.php or to a site-specific plugin.

3. Make sure you replace the list of feeds with the desired feed.

📝Note: Do not remove HTML tags from the summary and/or use the item content instead of its description.

function tifd_summary_input( $description, $content, $feedURL, $item ) {
    //If you want to use the item content as the description. If not, then remove this line
    //If feed don't have content meta, $content is already equal to $description
    $description = $content;
    
    //List of feeds you don't want to remove HTML tags
    $feedList = array (
        'http://www.gumdust.com/feed',
        'http://b-website.com/feed'
        );
    
    //Remove the item HTML tags (as in the default hook) if not in the above list
    if( !in_array( $feedURL, $feedList ) ) {
        $description = trim( strip_tags( $description ) );
    }
    
    //Remove hellip (as in the default hook) 
    //Keep in mind that it will be added later in the plugin render
    $description = trim( chop( $description, '[…]' ) );
 
    return $description;
}
add_action( 'init', 'feedzy_summary_input_remove', 99 );
function feedzy_summary_input_remove() {
	remove_filter('feedzy_summary_input', array( Feedzy_Rss_Feeds::instance()->get_admin(), 'feedzy_summary_input_filter' ), 9);
}
add_filter( 'feedzy_summary_input', 'tifd_summary_input', 10, 4 );

Example ​

We have used an RSS feed that contained tables. Before using the code snippet, the description was delivered on the same line without taking into consideration the existing table. After using the code snippet, the table is displayed as expected.

Feed Before

Feed After

Keep HTML in imported posts ​

When you import feed items as posts, the magic tag you use in the Content field decides whether HTML and links are kept:

  • [#item_description] imports the item summary as plain text. Feedzy removes all HTML tags from it, so links and formatting are lost.
  • [#item_content] imports the item content with its HTML, including links. If the feed has no separate content element, Feedzy uses the item's description instead and keeps its HTML.

To keep links and formatting in imported posts:

1. Go to Feedzy > Import Posts and edit the import job.

2. Under Step 3: Map content > General, find the Content field.

3. Replace [#item_description] with [#item_content].

4. Under Step 4: General feed settings > Advanced, make sure Strip HTML Tags is turned off. When it is on, Feedzy converts all imported content to plain text.

5. Save the import job.

Changes apply only to posts imported after you save. Open a newly imported post to confirm that its links and formatting are present.

If the feed provides both content and description elements and you want the HTML from the description specifically, you can map it with the [#item_custom_description] custom tag. Custom tags require a Feedzy Pro plan that includes them; see How do I extract values from custom tags in Feedzy?.

Was this helpful?