Try our conversational search powered by Generative AI!

TinyMCE V2 - Remove the height and width attribute from images in editor.



I've been trying to programmatically remove the height and width attributes from the images via TinyMce

I've tried added a few things to to my initialization, but not of them seem to work.

It should be something simple like this:

 .AddSetting("extend_valid_elements", "img[class|src|id|alt]")

But that doesn't seem to remove the height and width attributes. 

invalid_elements only works on elements, not attributes.

image_dimensions removes the dimentions settings in the editor but not the code


Apr 21, 2020 19:50


I never tried this but have you tried adding following setting in the initialization module or tiny init method

 image_dimensions: false

Apr 23, 2020 7:28

Hi veckly,

It's strange, it seems like image_dimensions should work.

You could try something like this: (there may be a better example somewhere, this was just the first I found).

To use it you'd need to do something like:

.AddExternalPlugin("remove-img-dimensions", "/ClientResources/Scripts/tinymce/remove-img-dimensions.js")

Where that path is, of course, the path to your JS file.

Documentation is here:

Edited, Apr 23, 2020 16:01

Hi Jake,

Logically it seems that image_dimensions: false would work.

But according to the documentation, and from what I've experenced, "This options allows you disable the image dimensions input field in the image dialog." It doesn't remove the attributes from the image tag in the code.   Also, it looks like this issue has been going on for a while now.

You can clear the dimentions in the input fields, but seeing that I managed hundreds of web authors having them all to remember to do this is an issue which can't be solved without a couple of  bottles of whatever poison you prefer.  

So clearing it out in the code is the best thing I can come up with and the plugin option may be the best.  I'll play around with that and see if I can find something that works.

I also need to add limits as to the images they can upload, and your blog posts have given me some pretty good advice and how to impliment that. 

Apr 23, 2020 18:52
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.