• Austin SEO
    • TastyPlacement in the Press
    • Meet the Team
  • Blog
  • Services
    • SEO Services
      • WordPress SEO Service
      • Magento SEO Services
      • Conversion Rate Optimization
      • SEO Audit Service
      • Why Google Certification Matters
    • PPC & Adwords
      • Adwords & PPC Management
      • Remarketing Services
      • Display Ad Management
      • Facebook Ad Management
      • Google Ad Grants Management for Non-Profits
      • Adwords App Install Ad Management
      • Product Listing Ad Management
    • Analytics & Data
      • Analytics and Monitoring
      • Google Tag Manager Experts
      • Data Studio Development & Consulting
    • Social Media & Local Marketing
      • Social Media Marketing
      • Local SEO
    • Web Development
      • Mobile Website Design
      • WordPress Development
  • Case Studies
    • SEO Case Studies
      • SEO Case Study: We Beat Lowes, Then We Beat Home Depot
      • SEO Case Study: Total Domination in Houston for Medical Provider
    • Analytics Case Studies
      • Case Study: Updated Design Yields 43% Increase in Conversion Rate
      • Case Study: PPC Optimization Yields Tripled Conversion Rate
    • Social Media Case Studies
      • Social Media Case Study: Hundreds of New Customers From Core Facebook Campaign
  • Portfolios
    • Display Ad Portfolio
    • Design Portfolio
    • Infographic Portfolio
    • SEO Testimonials
  • Contact
    • New Customers: Get to Know Us
    • Customer Service & Support
    • Referral Program
    • SEO Training Seminars
    • Job: Paid Search/PPC/Adwords Analyst
    • Job: Local Digital Marketing Specialist
    • Job: SEO/Marketing Junior Analyst
    • Privacy Policy & Terms of Use
  • Menu Menu

WordPress Stripping iFrame Elements? Here’s the Fix.

February 18, 2011/18 Comments/in Programming & PHP, WordPress/by Michael David

Elements like Google Map embeds get stripped out. Here’s the Fix.

If you have ever tried to enter a Google Map embed into a WordPress page or post, you’ve noticed that switching between “Visual” and “HTML” view in the page or post edit window strips the iFrame out–leaving you with broken code that displays nothing. Luckily, there is a fix.

You’ll need to find the functions.php file in your active theme folder. It’s a standard WordPress file, so it’ll be there. Next, we are going to add two short functions that change the way the WordPress editor handles iFrame code. You’ll want to insert the following lines of code before the closing “?>”  of your functions.php file.

// this function initializes the iframe elements 

function add_iframe($initArray) {
$initArray['extended_valid_elements'] = "iframe[id|class|title|style|align|frameborder|height|longdesc|marginheight|marginwidth|name|scrolling|src|width]";
return $initArray;
}

// this function alters the way the WordPress editor filters your code
add_filter('tiny_mce_before_init', 'add_iframe');

That’s it. You can test your mod by entering some iFrame code in the editor window and switching between  the visual and HTML editor.

Tags: SEO, tutorial, WordPress
Share this entry
  • Share on Facebook
  • Share on Twitter
You might also like
Google Announces New Link Disavowal Tool
Setting Up a Stripe.com Single Payment Page for WordPress
Getting Started With WordPress
How To Delete All WordPress Pending Posts
The Truth About WordPress Hosting
Siri Search Optimization
18 replies
  1. Derrick T Spruiell says:
    February 19, 2011 at 8:54 am

    Thanks for the post Nick, really search engine marketing has changed a lot in couple of years, let’s hope for the best. Thanks

    Reply
    • TastyPlacement (Michael) says:
      May 24, 2011 at 3:51 pm

      Nick…Michael, whatever.

      Reply
  2. Micah says:
    April 27, 2011 at 12:17 pm

    Thanks for the fix for this, looked all over the web for this particular answer. Worked perfectly.

    Reply
  3. web-developer says:
    May 12, 2011 at 12:41 pm

    With such hack you may break future WordPress versions.
    WordPress removes iframe when you switch from “HTML” to “Visual” tab in your editor because of the security reasons.
    You can use this plugin to insert iframe into post content using such shortcode: [iframe width=”640″ height=”480″ src=”http://player.vimeo.com/video/3261363″]. This way is much more flexible.

    Reply
  4. web-developer says:
    May 12, 2011 at 12:42 pm

    With your hack you may break future WordPress versions.
    WordPress removes iframe when you switch from “HTML” to “Visual” tab in your editor because of the security reasons.
    You can try this plugin to insert iframe into post content using such shortcode: [iframe width=”640″ height=”480″ src=”http://player.vimeo.com/video/3261363″]. This way is much more flexible.

    Reply
    • TastyPlacement (Michael) says:
      May 24, 2011 at 3:51 pm

      True, future versions might not work. That said, we advise our clients against installing a plug-in for something that can be solved at the theme level. I’ll probably get in trouble for saying this, but Plug-ins generally reduce WordPress performance.

      Reply
  5. Pedro Gomes says:
    September 30, 2011 at 3:16 am

    FINALLY a simple solution that REALLY works!

    I had to filter through dozens of posts in trendy blogs made by trendy idiots that don’t have a clue about what they are writing saying they had “solved the problem” and then introducing a plugin that even when it’s installed if you switch to visual the iframe STILL disappears.

    Thank you Michael for making this solution available, I’ll be linking to this post soon.

    Reply
  6. Vilius says:
    December 10, 2011 at 7:30 am

    Thanks, Michael, I spent 24 hours trying to fix the problem. Finally i found the solution :)
    What web-developer said earlier might be true, but same true is for plug-ins – authors sometimes loose interest in developing their plugins and this fact can bring the whole website down. That happened to me few times already. I prefer to stick to this version of hack and hope that Michael will find an alternative once the hack has been plastered up.

    Reply
  7. Vilius says:
    December 11, 2011 at 9:11 am

    Disabling Visual Editor ir profile does the job too and needs no coding or plugins.

    Reply
  8. Andy says:
    March 7, 2012 at 6:03 pm

    Thank you so much. This is a much better solution than adding another plugin into the mix.
    By the way, I really like the look and feel of your blog.

    Reply
  9. Evie Milo says:
    March 14, 2012 at 12:03 pm

    Thanks for this but it’s not fixed my issue – I’m trying to embed vimeo videos and despite wordpress now not stripping out the iframe because I’ve added this code to the functions.php file, it doesn’t display the vimeo video text info – like the title and byline – for some reason all the text gets stripped out and all you’re left with is the button to switch to full screen mode and the play icon.

    Reply
    • Michael David says:
      March 15, 2012 at 7:30 pm

      Hmmn…you might have something else going on with your template. Each wordpress template has a functions.php file, so they are subject to some variation. Another option for you might be to use of the alternative text editors for wordpress which replace the default text editor in the admin.

      Reply
  10. silver darling says:
    April 3, 2012 at 8:05 am

    Thanks, that iframe mauling was annoying; working fine for wordpress ms 3.0.1

    would be good to see a ‘super’ functions.php in wp multisite to take functions wanted across all themes

    Reply
  11. Nathan says:
    May 10, 2012 at 12:46 pm

    You just saved me HOURS of time/hassle/etc. Thanks for posting this.

    Reply
  12. Jim says:
    July 17, 2013 at 6:02 am

    The fix works great except:

    When I define the width and height in a CSS style sheet and not in the iframe itself the visual editor inserts its own width and height values. Is there a way to prevent this?

    Example – Custom CSS
    #IDXSearchBox {width:900px; height: 800px; overflow-y: scroll; overflow-x: hidden;}
    Then this

    Gets turned into this

    Reply
  13. Jim says:
    July 17, 2013 at 6:06 am

    I put the HTML in the previous post and assume it was taken out. I’ve used [ and ] here to allow the code to show:

    Then this
    [iframe id=”IDXSearchBox” src=”http://mrmlsmatrix.com/Matrix/public/IDX.aspx?idx=####”][/iframe]
    Gets turned into this
    [iframe id=”IDXSearchBox” height=”240″ src=”http://mrmlsmatrix.com/Matrix/public/IDX.aspx?idx=####” width=”320″][/iframe]

    Reply
  14. Fotógrafo em Coimbra says:
    January 15, 2018 at 4:16 pm

    Oh dear, finally I’ve find something that really works!
    Thank you so much

    Reply
  15. Ankit Agarawal says:
    December 17, 2018 at 5:36 am

    Thanks for posting but dear it’s not working for my side. WordPress again strip my iframe code.
    Any help please ?

    Reply

Leave a Reply

Want to join the discussion?
Feel free to contribute!

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Tutorials & Case Studies

  • Analytics
  • Case Studies
  • Infographics
  • Internet Marketing
  • Local Maps and Local Listings
  • Magento
  • Mobile SEO
  • Our Book: SEO for Wordpress
  • PPC
  • Programming & PHP
  • SEO
  • SEO Power Tools
  • SEO Resources
  • Social Media Marketing
  • Web Design
  • WordPress

Our Most Recent Tutorials & Case Studies

  • Infographic: Fonts & Colors That Drive the World’s Top Brands
  • Research Shows a 23% Divergence Between UA and GA4
  • How to Track Google Analytics Conversions on BuilderTrend’s iFrame Form
  • Test Results: How to Stop Google Re-Writing Your Title Tags in the SERPs
  • Pro Tip: Track Your Website Goals in Google Analytics (and More)

Search

Archives & Tutorial Categories

  • Analytics
  • Case Studies
  • Infographics
  • Internet Marketing
  • Local Maps and Local Listings
  • Magento
  • Mobile SEO
  • Our Book: SEO for Wordpress
  • PPC
  • Programming & PHP
  • SEO
  • SEO Power Tools
  • SEO Resources
  • Social Media Marketing
  • Web Design
  • WordPress

Austin SEO Company, TastyPlacement

TastyPlacement
4150 Freidrich Ln Ste C
Austin, TX 78744
Tel: (512) 535-2492

Google Maps: Get Directions or Read Our Awesome Reviews

Quick Navigation: Our Most Important Pages

  • Austin SEO [Home]
  • WordPress SEO Service
  • PPC Management
  • Social Media Marketing
  • Analytics and Monitoring
  • Remarketing Experts
  • Conversion Rate Optimization
© Copyright - TastyPlacement. Made in Austin, Texas
  • Twitter
  • Facebook
Facebook and Twitter Can Help Your Rankings From the Wordpress SEO book Book Excerpt: The Ultimate WordPress Robots.txt File
Scroll to top