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
- Upload the
tinymce_valid_elements/directory and its contents to the/wp-content/plugins/directory - Activate the plugin through the ‘Plugins’ menu in WordPress
- 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.
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.
hi. Thanks for plugin
perfect.
Regards
Thnks. Very good plugin.
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
Thank you. This plugin saved the day.
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
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).
Still doesn’t work with Youtube’s “embed” code…
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?
Never mind! It strips it out of the comment when you’re not logged in as an administrator.
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.
didn’t work
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.
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.
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.
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);
}
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.
The message above stripped out my tags
Should have been can this plugin prevent WP replaceing
form name=”form1″
with
form
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
OMG .. Your the man!!
This even works after a wordpress upgrade indeed .. thanx a lot!
GrtzG
Thanks a lot… worked perfectly for a solution for google maps iframe code. but did not do well with tiny mce advanced.
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!
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!
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
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!
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
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
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?
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
Good website design You have
wow! you did it!!! i have a question: where i am supposed to add downloaded xml for some european languges?
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