Drupal 8 and 9: How to avoid stripping of iframe tags like Google Maps and YouTube

By default, the text formatting for Drupal has internal controls for security. Text formats define how text is filtered for output and how HTML tags and other text is displayed, replaced, or removed. Please take note: improper text format configuration is a security risk. Basic text format is normally reserved for non-admins only, while the Full text format should be reserved for full administrators of the website who can use unrestricted tags including iframe tags. 

Therefore, when embedding iframes such as Google Maps or YouTube videos, one should switch to Full HTML, toggle to source code view then paste and save the embed code.

To assign the same permissions and allowed html tags this time to the Basic Text formatting, for example, you wish to provide to your non-full administrators like publishers and encoders. We need to allow iframe tag in the Basic text formatting. This text format setting has an enable filter by default: Limit allowed HTML tags and correct faulty HTML, again for security purposes. To override the iframe code and tag insertion:

  1. Go to Text formats and editors /admin/config/content/formats
  2. Edit, Basic text HTML (this text formatting allowed for administrators only by default, a necessity to allow only admins to embed iframe tags which poses some security risks)
  3. Under Limit allowed HTML tags and correct faulty HTML > Allowed HTML tags, add the <iframe> tag to the list

If for some reason, your Drupal 8 setup is still stripping your iframe tags and code (we have experienced one template issue which strips the code from the frontend only, while iframe is visible from the backend), you may wish to try the following modules which helped us with the issue:

Image banner credit: Technology photo created by creativeart - www.freepik.com

By: Jerome Esperanza
In:
Jerome Esperanza's picture
Jerome Esperanza

Let us help you create a practical and winning marketing strategy to boost a cost-effective online presence and search visibility here. WebMedia is a digital marketing agency in Metro Manila, Philippines with a seasoned team of experts and specialists. We specialize in web design, development, Google and general search optimization (SEO), and online marketing in general.

Leave a Comment

All fields with * are required.

Training courses for website design, SEO and digital marketing in Manila, Philippines

Get in touch with us!

Telephone: (+63 2) 7625-6994 | (+63 2) 8632-1748
Mobile: (Globe) +63 945 217-3344
E-mail: info@webmedia.com.ph

start typing and press enter to search