I am trying to hide the Alignment radio buttons for images uploaded to the post content area, but can’t figure out how to add a custom CSS or JS file to the Image Editor dialog.
I’ve successfully added a filter to the tiny_mce_before_init action hook to remove alignment buttons from the TinyMCE text editor, but am unsure how to do the same with the image editor.
I’ve tried a jQuery hack, but it doesn’t seem to take:
$('.mceWrapper iframe').load( function() {
$(this).contents().find('tr.align').hide();
});
Looking at it in detail it seems that you can’t alter the image editor just in some details. The only thing you can do is to replace the image editor with a slightly modified copy. I’ll explain shortly how this can be done.
One last note: It would proably better if you did put this in a Plugin and not in your theme. Anyway, to make this answer shorter I explain how to put this in your theme.
1. Remove default Image Editor
2. Copy and change the Image Editor
Copy wp-includes/js/tinymce/plugins/wpeditimage to your theme folder.
Alter it the way you like. The easiest way to get rid of the alignment options would be to change line 55 from
to
3. Add the altered Image Editor
The function you’re looking for, to add CSS to the MCE editor is called add_editor_style. I had a go at getting this to work but a quick five minute hack didn’t work for me. According to the codex that is the right way of doing it though.
You can just hide it with your CSS. If your theme has a css file for your admin dashboard (for custom forms etc) then just add this to that file;
If your theme doesn’t have a CSS file for the admin dashboard then you can put this in your themes’
functions.php
file instead;Note the alignment value will be still be saved as whatever it was prior to editing.