WordPress PluginAllows one to add “invalid” and custom HTML elements to the TinyMCE editor.
Download:

tinymce_valid_elements.zip (version 0.3)

Tags: tinymce, editor, html, element

Requires at least: 2.5

Tested up to: 2.7.1

Description

By default, WordPress’ WYSIWYG editor, TinyMCE, will strip out of your Article and Page HTML code any elements that are not defined as “valid elements”; this can be extremely annoying (especially if you want to include iframes).

This plugin will allow you to extend what TinyMCE defines as “valid elements”. By doing so, TinyMCE will no longer remove, delete, or strip-out the additional elements and attributes that you specify.

** NOTE: Make sure after you add elements or attributes you do a hard refresh (ctrl + F5) of your browser on a TinyMCE screen (editing or creating a page/post) so that the TinyMCE cache will be refreshed! You will not see your changes until you do this!

Installation

  1. Upload the tinymce_valid_elements/ directory and its contents to the /wp-content/plugins/ directory
  2. Activate the plugin through the ‘Plugins’ menu in WordPress
  3. Go to Manage -> TinyMCE Valid Elements and add some elements and attributes.

Read the Help Section at the bottom of the management page.

Frequently Asked Questions

I added new elements/attributes, why is TinyMCE still stripping it out?

  • Most likely, you need to do a hard refresh of your browser (ctrl + F5). Your JavaScript cache needs to be refreshed.

47 Responses to “TinyMCE Valid Elements”


  1. 1 Tony

    Hi,

    thanks for this. I spent yesterday evening trying to figure out how to do exactly this, and gave up. Now I find your plugin and I don’t have to figure it out anymore. Good stuff!

    Tony.

  2. 2 baron

    hi. Thanks for plugin

    perfect.

    Regards

  3. 3 EHocam

    Thnks. Very good plugin.

  4. 4 Wolfgang

    Almost perfect. Still have a problem. I would like to enable one further attribute for element . When doing so my attribute is enabled while all *default* attributes (like “class”) are gone. How can I tell this plugin to just *add* my attribute?
    Greetz, Wolfgang

  5. 5 charmed

    Thank you. This plugin saved the day.

  6. 6 Clint

    I have tested this on two WordPress 2.7 instances. It worked flawlessly on one instance but I noticed a bug on the other instance. The HTML form on the “Tools > TinyMCE Valid Elements” page incorrectly has its action attribute set to “/cgi-system/php.cgi” instead of “/{your wordpress install dir}/wp-admin/tools.php”.

    One workaround is to use a browser plugin that allows you to modify the DOM in real-time. For example, I used a Firefox plugin called Firebug (https://addons.mozilla.org/en-US/firefox/addon/1843) to change the form action to the correct URL so that the POST works–only a mild annoyance when you consider that you’re not editing the valid fields very often.

    Thanks for sharing such a handy resource! Please consider adding it to the standard WordPress Plugins Directory so that more people can benefit from it! http://wordpress.org/extend/plugins/

    /cgi-system/php.cgi

  7. 7 xiffy

    I had the same problem as Clint is describing, we have a WPMU installation with subdirs instead of sub-domains. What happened was that all POSTS went to the main blog while editing the settings of a sub blog.
    I’ve corrected this by replacing $_SERVER['SCRIPT_NAME'] by $_SERVER['REQUEST_URI'] resolved this problem.
    Please consider this patch for your next release.

    Besides this bug, I was relieved to find this plugin because I had spend way to many time resolving this i-frame issue (which needed TWO plugins on a WPMU installation, one unfiltered-mu for the WP side of the story and this one for the RTE side of the story).

  8. 8 Julián Rodriguez Orihuela

    Still doesn’t work with Youtube’s “embed” code…

  9. 9 Maria

    But this allows those elements to be entered into comments. I use iframes on two pages on one of my sites (a google map and a databases page maintained by someone else) and would love to not have them messed up by the Visual editor, but I don’t want people to be able to put iframes into their comment text either. Any solution to that problem?

  10. 10 Maria

    Never mind! It strips it out of the comment when you’re not logged in as an administrator.

  11. 11 jezzadot

    thanks for the great plugin. i made a few mods to get it running in wordpress mu. posted info here: http://www.sharpdotinc.com/jdost/2009/03/17/update-tool-for-wordpress-mu-and-allowable-tags/ i *think* it gets rid of the need to use unfiltered-mu.

  12. 12 Mike

    didn’t work

  13. 13 Czymra

    This is great! Finally!
    Thank you very much.

    When I try to remove an attribute however this error is returned:
    Cannot load tinymce-valid-elements/tinymce_valid_elements.php?page=tinymce-valid-elements/tinymce_valid_elements.php.

    Considering that the plugin allows for clearing of the database upon deactivation though, it’s a rather quick process to just re-enter the info from scratch if necessary.

  14. 14 Jaysin

    Nice plugin, was looking for a way so it didn’t strip the iframe and could make it easier to embed google maps. I am using it on 2.8 alright, but I can’t delete attributes.

  15. 15 Claire

    Thanks for this plugin. I am still trying to figure out how to allow PHP code in posts without it being stripped by the TinyMCE editor when switching between Visual and HTML modes.

    I have something like this:

    With the plugin, I can get the phpcode tag to stay, but the PHP code in the middle still gets stripped out since it can’t be added as an HTML tag.

    Any ideas would be much appreciated.

  16. 16 verex

    Add this code to tinymce_valid_elements.php and users without unfiltered_html capability will be able to add tags validate by this plugin too.

    /**
    * Add $allowedposttags for enable tags for users without unfiltered_html capability
    *
    * @param $allowedposttags assoc. array of $allowedposttags
    * @return $allowedposttags the changed assoc. array
    */
    function tmve_allowed_elements($allowedposttags) {
    $elements = tmve_get_element_map();
    foreach ( $elements as $element => $attributes ) {
    if (count($attributes) > 0 ) {
    foreach ($attributes as $attribute) {
    $allowedposttags[$element][$attribute] = array();
    }
    } else {
    $allowedposttags[$element] = array();
    }
    }

    return $allowedposttags;
    }

    if (!CUSTOM_TAGS) {
    $allowedposttags = tmve_allowed_elements($allowedposttags);
    }

  17. 17 Ben

    Can I use TinyMCE Valid Elements to prevent WordPress replacing

    with

    when switching between visual & html editors.

    I entered form and name as the elements but it won’t allow adding the name=form1″ and doesn’t seem to work with these element on its own.

    Any suggestions?

    Thanks.

  18. 18 Ben

    The message above stripped out my tags :-(

    Should have been can this plugin prevent WP replaceing
    form name=”form1″
    with
    form

  19. 19 Nathan

    I’m trying to use this plugin to stop the removal of and tags, but it doesn’t seem to be working. I’ve added td as an element, and nothing changes.

    I’ve tried entering test as an element, and it will leave well enough alone.

    Any tips?

    Cheers,
    Nathan

  20. 20 Gerard

    OMG .. Your the man!!

    This even works after a wordpress upgrade indeed .. thanx a lot!

    GrtzG

  21. 21 Martin D.

    Thanks a lot… worked perfectly for a solution for google maps iframe code. but did not do well with tiny mce advanced.

  22. 22 Alex

    I have tried this with 2.9.1 & TinyMCE Advanced. It worked fine. I wish though that there would be an official statement =) saying that this plug works with 2.9.1 and TinyMCE Advanced…will make things feel warmer inside…lol

    Anyhow, great plugin!

  23. 23 paul

    Thank you so much! I tested it with WP 2.9.2 and everything seems to work fine. I can’t believe they don’t incorporate something like this into WP core. Please, please keep updating this plugin so it continues to work with future versions of WP. It’s a life saver! Thanks again!

  24. 24 Robert

    I am using the Tiny MCE advanced and valid elements plugins, but I cannot seem to get adding a class to a dl, dd, dt item to work. I need these to be accepted in order for an accordian to work.

    Ive added the dl elements and a class attribute, refreshed on the editor page, and when i add dl class=”kaccordian” it removes the class when I hit publish page..

    Anyone shed some light on this? Thanks

  25. 25 Mobil Pete

    Hi,
    I always wonder why tinymce doesnt have this option included. There is hardly anything more annoying than having your code deleted over and over again. Tried raw html plug-in before, still the post got stripped. now hoping this will do the trick – why is this not officially part of tinymce (advanced)?!

    thx 4 the plug-in work!

  26. 26 Joerg

    I’m trying to include a Java applet in a WP page. Your very cool plugin allowed my to use the tag, but for some reason the tags within the section are still stripped, even though I added all required attributes and did Ctrl-F5. Any idea?

    Thanks a lot,
    Joerg

  27. 27 Joerg

    Argh! The tags have been stripped from my above comment, too! OK, without angle brackets this time:

    I’m trying to include a Java applet in a WP page. Your very cool plugin allowed my to use the “applet” tag, but for some reason the “param” tags within the “applet” section are still stripped, even though I added all required attributes and did Ctrl-F5. Any idea?

    Joerg

  28. 28 Peter H.

    Having permission problems. I am logged in as the administrator but get this error message when trying to delete an incorrect tag

    “You do not have sufficient permissions to access this page.”

    Can anyone help on this?

  29. 29 Brian D

    Thanks a million for this plugin. It came at the end of a 6 hour hunt for how I could use iframes (Amazon ads) in a post. It works great with WP v2.92 and my ads are finally working as they should. I’m praying a future upgrade of WP or TinyMCE Advanced doesn’t break it!

    Regards
    Brian

  30. 30 Mannie

    Good website design You have

  31. 31 staima

    wow! you did it!!! i have a question: where i am supposed to add downloaded xml for some european languges?

  32. 32 Dainis W. Michel

    Hey, for some reason, I’m still getting rewritten code.

    I described the issue here:
    http://wordpress.org/support/topic/396411?replies=2#post-1505512

    Can you help me out?

    Best,
    Dainis

  1. 1 New WordPress Plugin: TinyMCE Valid Elements at engfer(s)
  2. 2 How To Allow Stripped Element Attributes in Wordpress’ TinyMCE Editor at engfer(s)
  3. 3 WordPress Plugin Releases for 11/09 | bloground.ro - Blogging resources, WordPress themes and plugins for your development
  4. 4 WordPress Plugin Releases for 11/09 | Wordpress Blog NL
  5. 5 WordPress плагины за 09/11/2008 | Всё для WordPress (ВордПресс). Модули, шаблоны (скины) для Wordpress.
  6. 6 WordPress Plugin Releases for 11/09 | BlogBroker24-7
  7. 7 leg med nye medier. Eller noget.
  8. 8 Programm-Quellcode (Quelltext) mit Wordpress anzeigen » Programmierung
  9. 9 Using SyntaxHighlighter in WordPress : André’s techblog
  10. 10 Update tool for Wordpress MU and allowable tags
  11. 11 Bartoz Blog » Blog Archive » TinyMCE Valid Elements
  12. 12 WP-Syntax Editor Integration Plugin – WP-Syntax im WordPress Editor nutzen « Abraxas
  13. 13 Wordpress.mu – HTML tagy v editoru | KaRLiK's PeRSoNaL Mu.BLoG
  14. 14 Amazon and the iFrame… a solution!
  15. 15 Medienlobby » Google Maps in Wordpress einbinden ohne API Key

Leave a Reply