Save With Ctrl+S or Cmd+S in the Classic Editor
Lets you press Ctrl+S (Cmd+S on a Mac) to save a draft or update a published post in the classic editor, instead of the browser's save dialog.
Opens WPIDE on
Code
add_action( 'admin_footer-post.php', 'wpide_ctrl_s_script' );
add_action( 'admin_footer-post-new.php', 'wpide_ctrl_s_script' );
if ( ! function_exists( 'wpide_ctrl_s_script' ) ) {
function wpide_ctrl_s_script() {
if ( function_exists( 'use_block_editor_for_post' ) && use_block_editor_for_post( get_post() ) ) {
return; // The block editor already supports the shortcut.
}
?>
<script>
( function ( $ ) {
function save( event ) {
if ( ! ( event.ctrlKey || event.metaKey ) || 's' !== String( event.key ).toLowerCase() ) {
return;
}
event.preventDefault();
var $draft = $( '#save-post:visible' );
if ( $draft.length ) {
$draft.trigger( 'click' );
} else if ( 'publish' === $( '#original_post_status' ).val() ) {
$( '#publish' ).trigger( 'click' );
}
}
$( document ).on( 'keydown', save );
$( document ).on( 'tinymce-editor-init', function ( e, editor ) {
editor.on( 'keydown', save );
} );
} )( jQuery );
</script>
<?php
}
}
Notes
Unpublished posts are only saved as drafts, never published, by the shortcut.
How to add this snippet
- Install WPIDE on your WordPress site (it is free) and open Code Snippets.
- Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
- It is added inactive: review the code and settings, then switch it on.