下記コードをfunctions.phpへ記述追加
1 2 3 4 5 6 7 |
// メディア追加時のwidth/height自動追加を削除 function my_remove_width_attribute( $options ) { if ( $options['tinymce'] ) { wp_enqueue_script( 'remove_width_attribute', get_template_directory_uri() . '/js/remove_width_attribute.js', array( 'jquery' ), '1.0.0', true); } } add_action( 'wp_enqueue_editor', 'my_remove_width_attribute', 10, 1 ); |
remove_width_attribute.js
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
(function ($, wp, _) { if (!wp.media.events) { return; } wp.media.events.on('editor:image-update', function (options) { var editor = options.editor, dom = editor.dom, image = options.image; dom.setAttribs(image, { 'width': null, 'height': null }); }); })(jQuery, wp, _); |