Float images in content

You need to setup CSS settings for alignleft class of your theme: .alignleft, img.alignleft { /* … */ display: inline; float: left; /* … */ } And you need to add editor stylesheet where the same CSS will be presented. Create editor-style.css file in your theme, put content CSS settings there and call add_editor_style(); from … Read more

How to get Text Selection in WordPress Editor

The visual editor is an TinyMCE implementation. The first way to repace a selected text, is to write a plugin for the TinyMCE. If you do not want to write a plugin, use the tinyMCE object: add_action( ‘admin_footer’, ‘tinyNagging’ ); function tinyNagging() { echo ‘ <script type=”text/javascript”> jQuery(document).ready( function() { window.setInterval( function(){ var selectedText = … Read more

Define multiple Gutenberg editor widths

You may need to use the same approach that conditional editor stylesheets require now (for TinyMCE). function my_theme_add_editor_styles() { global $post; $post_type = get_post_type( $post->ID ); $editor_style=”editor-style-” . $post_type . ‘.css’; add_editor_style( $editor_style ); } add_action( ‘pre_get_posts’, ‘my_theme_add_editor_styles’ ); This snippet is from a Hongkiat article describing the process. Note: You would then have a … Read more

WordPress post editor crashes with Polyfill typo

Here is an answer: WordPress v5.0.3 Gutenberg & JS error “Uncaught SyntaxError: missing ) after argument list” The simplest way: Find & delete PHP Hook which added ‘defer’ to script (in the function.php file). Or if you have skills you can edit the code of the hook. Reason: Confusion/conflict with quotes (‘ & “) witch … Read more

Remove all table widths from editor content

I would approach this by modifying the attributes allowed in the table, tr, and td markup from wp_kses. wp_kses is a function that runs on the content to filter out unwanted tags and attributes. It stands for KSES Strips Evil Scripts, but it does much more than that. It’s a large and sometimes convoluted function, … Read more

Add option for editors through `register_setting`

To allow users with capabilities other than manage_options to save a setting you can use the option_page_capability_{$option_page} hook. Despite the name, {$option_page} is the option group, which is what you set for the first argument of register_setting() and settings_fields() on your options page. So if you registered a setting: register_setting( ‘wpse_310606_setting_group’, ‘wpse_310606_setting’ ); You can … Read more