Support

Account

Home Forums ACF PRO ACF & HTML Editor Syntax Highlighter

Solving

ACF & HTML Editor Syntax Highlighter

  • Is it possible to have the “HTML Editor Syntax Highlighter” plugin work on the ACF Wysiwyg Editor?

  • That would be awesome.

  • Hi @syncopatemedia

    the ACF wysiwyg field is using the built in editor in WordPress so it should be possible. However I think this falls more on the HTML Editor Syntax Highlighter author. I’m guessing he/she targets only the regular editor specifically and would have to add in the ability to target ACF editors as well.

  • I had to hack my own solution to get the syntax highlighting to show up for the wysiwyg editor. It would be nice if it was built in. Simply insert this code in your functions.php file to get code mirrors’ syntax highlighting:

    /* ADD CODE MIRROR CSS */
    function admin_style() {
    wp_enqueue_style(‘admin-styles’, ‘https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.48.4/codemirror.css’);
    }
    add_action(‘admin_enqueue_scripts’, ‘admin_style’);

    /* ENQEUE CODE MIRROR JS */
    function my_enqueue() {
    wp_enqueue_script(‘code_mirror_script1’, ‘https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.48.4/codemirror.js’);
    wp_enqueue_script(‘code_mirror_script2’, ‘https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.48.4/mode/xml/xml.js’);
    }
    add_action(‘admin_enqueue_scripts’, ‘my_enqueue’);

    /* ADD CODE MIRROR ADDITIONAL STYLES */
    add_action(‘admin_head’, ‘custom_css’);
    function custom_css() {
    echo ‘
    <style>
    .tmce-active .mce-tinymce{display:block !important;visibility:visible !important;}
    .html-active .mce-tinymce{display:none !important;visibility:hidden !important;}
    .tmce-active .CodeMirror{display:none;}
    </style>
    <script>
    jQuery(document).ready(function($){
    function rundCodeMirror(){
    var areas = document.getElementsByClassName(“wp-editor-area”);
    for(var i = 0; i < areas.length; i++) {
    CodeMirror.fromTextArea(areas.item(i), {
    mode : “xml”,
    htmlMode: true,
    lineNumbers: true
    });
    }
    }
    setTimeout(rundCodeMirror, 1000);
    });
    </script>
    ‘;
    }

Viewing 4 posts - 1 through 4 (of 4 total)

The topic ‘ACF & HTML Editor Syntax Highlighter’ is closed to new replies.