F2P Filter: When Using Word Trimming, Import Missing Tags in the Post Content

Sometimes, when using the Word Trimming feature in Feed to Post, some tags in the original posts will get removed from the content you are importing.

You can add the below filter if you’d like to be able to keep the missing tags when you are using this feature. 

This example uses the  <img>  tag as an example, for cases when the images are stripped from the content when applying any form of word trimming.

add_filter('wprss_ftp_trimming_keep_tags', function($tags) {
        $tags = array_merge($tags, array('img'));
        $tags = array_flip($tags);
        $tags = array_keys($tags);
        
        return $tags;
});

An explanation of how it works

The word trimming feature works by removing all tags, trimming what is left, and then adding the tags back. This ensures that content doesn’t get trimmed in the middle of a tag, thus breaking the HTML and that only actual text gets counted towards the “words” that get trimmed. When adding the tags back into the content, however, only some are processed.

By default, the tags that get added back are the following:  <p> <br>,<em> <strong> <a>>/code> .

This is deliberate and is done to improve security. This list may be changed via the  wprss_ftp_trimming_keep_tags  filter for Feed to Post as shown above.


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