How to remove keyboard shortcuts in tinyMCE 4?

I was wondering if anybody could provide me a solution for removing keyboard shortcuts from tinyMCE in WordPress 4.0?
As I’m using frontend text editor, I want to disable ALT + SHIFT + M (opens media gallery) and ALT + F (opens full screen and users can’t add brackets opening)

Any help would be appreciated

Related posts

Leave a Reply

1 comment

  1. Here’s an elegant solution (original answer here), just add this to your functions.php file:

    <?php
        add_action( 'wp_tiny_mce_init', function () {
    ?>
        <script>
            function wp_disable_shortcuts_tiny_mce_init(editor) {
                editor.on('init', function () {
                        this.addShortcut('alt+ctrl+f', '', function () {}); //altgr is alt+ctrl
                        this.addShortcut('alt+ctrl+g', '', function () {}); //just in case...
                        this.addShortcut('alt+shift+m', '', function () {});
    
                        //you could add a for loop to disable multiple shortcuts as in OP's answer
                        // var ctrls = [ 'a', 'b', 'c', 'd' ];
                        // for( var i = 0; i < ctrls.length; i++ ){
                        //     this.addShortcut('ctrl+' + ctrls[i], '', function () {});
                        // }
                    });
                }
            </script>
    <?php
        });
        function wp_disable_shortcuts_tiny_mce_before_init( $mceInit ) {
            $mceInit['setup'] = 'wp_disable_shortcuts_tiny_mce_init';
            return $mceInit;
        }
        add_filter( 'tiny_mce_before_init', 'wp_disable_shortcuts_tiny_mce_before_init' );
    ?>
    

    And here is a brief description of the functions and filters used.

    This filter grants developers access to the TinyMCE settings array,

    add_filter( 'tiny_mce_before_init', 'wp_disable_shortcuts_tiny_mce_before_init' );
    

    There we can hook our js function on TinyMCE setup using this:

    function wp_disable_shortcuts_tiny_mce_before_init( $mceInit ) {
        $mceInit['setup'] = 'wp_disable_shortcuts_tiny_mce_init';
        return $mceInit;
    }
    

    And finally, this action,

    add_action( 'wp_tiny_mce_init', function(){ ... });
    

    Fires after tinymce.js is loaded, but before any TinyMCE editor instances are created. In here we create our javascript function which will disable editor shortcuts on init by replacing them with no-op functions.

    Hope this helps.