How to Prevent and Remove Unwanted Inline Styles in Advanced Editor Tools Tables
Content
Many users of the Advanced Editor Tools plugin (formerly TinyMCE Advanced) encounter a common and frustrating issue: the editor automatically adds inline styles to tables. This behavior can override your theme's carefully crafted CSS, making tables look bad on both desktop and mobile views. If you've struggled with style="width: 50%;" attributes appearing in your table cells or unwanted borders, this guide is for you.
Why Does This Happen?
This behavior originates from the underlying TinyMCE editor library, not necessarily from the Advanced Editor Tools plugin itself. The TinyMCE table plugin is designed to help users visually create and resize tables directly in the editor. To do this, it applies inline styles (like widths and heights) to table elements so that what you see in the editor (WYSIWYG) closely matches the front-end display. While helpful for some, this feature is often unwanted by users who prefer to control all table styling through their theme's CSS.
Common Solutions to Disable or Remove Inline Styles
1. Using a Custom Filter (Code Solution)
The most effective way to prevent the editor from adding certain inline styles is to use the tiny_mce_before_init filter in WordPress. This method tells the editor to treat specific styles as "invalid," preventing them from being added or retained.
Add the following code to your theme's functions.php file, preferably within a child theme to prevent loss during updates:
function tiny_mce_table_options( $initArray ) {
$initArray['invalid_styles'] = '{
"table": "height",
"tr": "width height",
"th": "width height",
"td": "width height"
}';
return $initArray;
}
add_filter( 'tiny_mce_before_init', 'tiny_mce_table_options' );
What this does: This code specifically targets the table, row, and cell elements (<table>, <tr>, <th>, <td>). It declares the width and height styles as invalid for these elements. As a result, the TinyMCE editor will strip these attributes out and will not add new ones when you interact with the table.
2. Manually Clean Existing Tables
For tables that already have inline styles, you can clean them up manually:
- In the WordPress editor, click on the table.
- Switch from the "Visual" tab to the "Text" (or HTML) tab.
- Locate and delete all
style="..."attributes from the<table>,<tr>,<th>, and<td>tags. - Switch back to the Visual tab to continue editing.
Pro Tip: For large tables, copy the entire HTML code into a plain text editor like Notepad++ and use its Find and Replace function to quickly remove all instances of style=" and their corresponding closing quotes and values.
3. Adjust Plugin Settings
The Advanced Editor Tools settings page offers an option to simplify the table properties dialog, which can help prevent users from accidentally applying advanced styles.
- Go to Settings > Advanced Editor Tools in your WordPress admin.
- Uncheck the option labeled "Show the advanced tabs in the table properties dialogs".
- Click "Save Changes".
This will hide options for setting border colors, background colors, and other advanced styling from the table properties popup, reducing the chance of inline styles being added.
Important Notes and Considerations
- Plugin Conflicts: Some users have reported that certain plugins, like newer versions of Yoast SEO, can cause the table row and column options to be grayed out. If you experience this, try temporarily disabling other plugins to identify a conflict.
- Pasting Tables: Be cautious when copying and pasting tables from external sources like Microsoft Excel or Google Sheets. These applications often include a large amount of extra HTML attributes and inline styles (e.g.,
data-sheets-*). Pasting directly into the 'Text' view and cleaning the code first is recommended. - Theme Styling: To ensure your tables look correct in the editor after removing inline styles, you may need to add custom CSS to your theme's
editor-style.cssfile. This will style tables within the WordPress editor to match your front-end theme.
By understanding why these inline styles are added and using the solutions above, you can regain full control over your table's appearance and ensure they are responsive and styled by your theme's CSS.
Related Support Threads Support
-
Disable Table Inline Styleshttps://wordpress.org/support/topic/feature-request-disable-table-inline-styles/
-
Table – Data sheet elementshttps://wordpress.org/support/topic/table-data-sheet-elements/
-
When inserting tables, is created that picks the first row text and duplhttps://wordpress.org/support/topic/when-inserting-tables-is-created-that-picks-the-first-row-text-and-dupl/
-
Remove Alternating Row Color & Lineshttps://wordpress.org/support/topic/remove-alternating-row-color-lines/
-
table function dose not work with Edgehttps://wordpress.org/support/topic/table-function-dose-not-work-with-edge/
-
How to prevent plugin from adding inline styles to tableshttps://wordpress.org/support/topic/how-to-prevent-plugin-from-adding-inline-styles-to-tables/
-
The “Reset table size” option is buggyhttps://wordpress.org/support/topic/the-reset-table-size-option-is-buggy/
-
Table Formattinghttps://wordpress.org/support/topic/table-formatting-6/
-
Table inline CSShttps://wordpress.org/support/topic/table-inline-css/
-
Row and Column options disabledhttps://wordpress.org/support/topic/row-and-column-options-disabled/
-
Table Settings stop working with Latest Versions of Yoasthttps://wordpress.org/support/topic/table-settings-stop-working-with-latest-versions-of-yoast/
-
Don’t add default styles to tableshttps://wordpress.org/support/topic/dont-add-default-styles-to-tables/
-
Stop Inline Styling on Tableshttps://wordpress.org/support/topic/stop-inline-styling-on-tables/
-
Unwanted inline styles added to tableshttps://wordpress.org/support/topic/unwanted-inline-styles-added-to-tables/
-
Table properties displaying inline problemhttps://wordpress.org/support/topic/table-properties-displaying-inline-problem/
-
Remove non-valid table options?https://wordpress.org/support/topic/remove-non-valid-table-options/
-
Table Issueshttps://wordpress.org/support/topic/table-issues-3/
-
Dismember a tablehttps://wordpress.org/support/topic/dismember-a-table/
-
New Table without inline stylehttps://wordpress.org/support/topic/new-table-without-inline-style/
-
Turn off default table styleshttps://wordpress.org/support/topic/turn-off-default-table-styles/
-
Table row colorhttps://wordpress.org/support/topic/table-row-color-2/
-
Copy-paste of table row forces in-line styleshttps://wordpress.org/support/topic/copy-paste-of-table-row-forces-in-line-styles/