Do you want to add HTML tags to your WordPress posts and pages? By default, WordPress editor doesn’t support some HTML tags, like iframe, name, class, etc. and may even strip them out while saving or publishing your article.
Instructions:
All you have to do is add this code to your theme’s functions.php file or in a site-specific plugin:
function fb_change_mce_options($initArray) { $ext = 'pre[id|name|class|style],iframe[align|longdesc| name|width|height|frameborder|scrolling|marginheight| marginwidth|src]'; if ( isset( $initArray['extended_valid_elements'] ) ) { $initArray['extended_valid_elements'] .= ',' . $ext; } else { $initArray['extended_valid_elements'] = $ext; } return $initArray; } add_filter('tiny_mce_before_init', 'fb_change_mce_options');
Note: If this is your first time adding code snippets in WordPress, then please refer to our guide on how to properly copy / paste code snippets in WordPress, so you don’t accidentally break your site.
If you liked this code snippet, please consider checking out our other articles on the site like: Best WordPress Page Builders (Compared).
How to you allow an attribute on ALL elements (wildcard) ?
Thanks for this one.
Anyway: I wanted to ask if there is a way to limit the allowed tags in the content, because i have “author” users, who should not e.g. add inline styles or use table, pre or h[1-x] tags…