Enable Tab Indent in WordPress Text-/HTML-Editor

If you don’t want to use a plugin to enable tab indent in WordPress text- and html-editor, you can use this snippet below:

// Enable tab indent in text editor
if( !function_exists('wpkb_enable_tabs_in_editor') ){
    function wpkb_enable_tabs_in_editor() {
        echo '<script>
        jQuery(function($) {
            $("textarea#content, textarea#wp_mce_fullscreen").keydown(function(e){
                if( e.keyCode != 9 ) return;
                var myTextarea = $(this)[0], start = myTextarea.selectionStart, before = myTextarea.value.substring(0, start), after = myTextarea.value.substring(start, myTextarea.value.length);
                myTextarea.value = before + "\t" + after; myTextarea.setSelectionRange(start+1,start+1);

    add_action('admin_footer-post-new.php', 'wpkb_enable_tabs_in_editor');
    add_action('admin_footer-post.php', 'wpkb_enable_tabs_in_editor');