E&T Filter: Import Missing Tags in the Excerpt

Sometimes, during import, when using the Excerpts word limit setting, some tags might be removed.

In these cases, please use the below filter if you’d like to be able to keep the missing tags in the excerpts. This example uses the <img> tag as an example:

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

    return $tags;
The explanation for this solution is as follows:

The creation of the excerpts works by removing all tags, trimming what’s 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:  <a> <span> <i> <b> <strong> <u>.

This is deliberate and is done to improve security. This list may be changed via the  wprss_et_allowed_tags_in_excerpts filter for  Excerpts & Thumbnails 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