Halloween Sale 15% off Ends in See the plans
PHP

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.

Don’t have WPIDE yet? Install it on your site

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

  1. Install WPIDE on your WordPress site (it is free) and open Code Snippets.
  2. Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
  3. It is added inactive: review the code and settings, then switch it on.

Have a snippet worth sharing?

Publish it to the library from WPIDE or right here. Sign in with any WordPress site that runs WPIDE, free or Pro. Public snippets are reviewed by the WPIDE team before they appear.

Which site should get this snippet?

Enter the address of your WordPress site. WPIDE opens there in a new tab with the snippet ready to review and save.

Remembered in this browser only, so you are asked once.

Report this snippet

Tell the WPIDE team what is wrong: broken code, something harmful, spam or copied work.