By default, Aggregator sanitizes imported feed content to help keep your site safe. This means certain HTML tags that can introduce security risks, such as <iframe>, are removed during import.
In some cases, a trusted feed may include embedded content that you want to keep. For example, a feed item may include a YouTube video inside an <iframe> tag. If the iframe is removed, the imported post will not show the embedded video.
Aggregator includes a developer filter that allows you to opt in to preserving specific HTML tags and attributes during import.
When to Use This
Use this approach when:
- You import content from a feed you trust.
- The feed includes iframe embeds, such as YouTube videos.
- The embed is missing from imported posts because the
<iframe>tag is being stripped. - You are comfortable adding a custom code snippet to your site.
Do not allow iframe embeds from feeds you do not trust. Iframes can load external content and should only be allowed when the source is trusted.
Add the Snippet
Add this snippet to your site:
add_filter( 'wpra.importer.allowedHtmlTags', function ( $tags ) {
$tags['iframe'] = array(
'src' => true,
'width' => true,
'height' => true,
'frameborder' => true,
'allow' => true,
'allowfullscreen' => true,
'loading' => true,
'title' => true,
);
return $tags;
} );
After adding the snippet, import a new item from the feed and check the imported post. The iframe embed should be preserved if it is included in the original feed content.
Note: If you are unsure how to add the code snippet to your site, see Adding Custom Actions and Filters.
Important Note
- This snippet allows iframe tags during the import process for all feed sources on the site. Only use it if you trust the feeds being imported.
- This change affects newly imported content. If a post was already imported before the snippet was added, the missing iframe will not automatically appear. You need to re-import the item.
If the Embed Still Does Not Appear
Check the following:
- Make sure the snippet is active on your site.
- Confirm that the original feed item includes an iframe.
- Import a new item or re-import the affected item.
- Check whether another plugin or custom code is removing iframe tags.
- Make sure your site is using Aggregator version 5.2.1 or later. The
wpra.importer.allowedHtmlTagsfilter was added in version 5.2.1.
Can I Allow Other Tags?
Yes. Developers can use the same filter to allow other HTML tags and attributes.
Only allow the tags you need, and only for feeds you trust.