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

Disable “preview changes” button

Please replace $post_type with your post_type in question, e.g. post, page, cpt_slug,… The function echoing the meta box with the preview button is called post_submit_meta_box. The condition to show the button is set with the function is_post_type_viewable. Following that: If the {$post_type}s flags publicly_queryable or _builtin and public are set to true the preview button … Read more

How can I automatically set a post slug based on the post title during post publish?

As long as haven’t touched the slug WordPress will generate a new one after you entered a title. Update To change other peoples slugs use a filter (not tested!): add_filter( ‘wp_insert_post_data’, ‘prevent_numeric_slugs’, 10, 1 ); function prevent_numeric_slugs( $post_data ) { if ( ! isset ( $post_data[‘post_title’] ) or ! is_numeric( $post_data[‘post_name’] ) ) { // … Read more

Hide tag and category boxes from the post editor

Using remove metabox function you can do this. Simply put this inside your themes functions.php file at very end. NOTE – unwrap <?php ?> if necessary. <?php function wpse60590_remove_metaboxes() { remove_meta_box( ‘categorydiv’ , ‘post’ , ‘normal’ ); remove_meta_box( ‘tagsdiv-post_tag’ , ‘post’ , ‘normal’ ); } add_action( ‘admin_menu’ , ‘wpse60590_remove_metaboxes’ ); ?>

How to get value of selected page template in Gutenberg editor?

I slightly modified SkyShab’s code, because it fired template change event on page load and it didn’t fire when template was changed to default (since getEditedPostAttribute( ‘template’ ) is then ”, which equals to null when testing for template change) const { select, subscribe } = wp.data; class PageTemplateSwitcher { constructor() { this.template = null; … Read more

Editing a Post, 99% CPU?

You may be dealing with the dreaded mod_security when your posting or updating . see if it’s enabled on the server first, if your using antimalware software it may be trying to scan on save . ok that’s the easy try . the next is to turn off your plugins . wsiwig editors., seo plugins … Read more