Is it possible to have the “HTML Editor Syntax Highlighter” plugin work on the ACF Wysiwyg Editor?
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>
‘;
}
You must be logged in to reply to this topic.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
🚨 The 2023 ACF Annual Survey closes tomorrow! This is your last chance to complete the survey and help guide the evolution of ACF. https://t.co/0cgr9ZFOJ5
— Advanced Custom Fields (@wp_acf) May 18, 2023
© 2023 Advanced Custom Fields.
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Cookie Policy. If you continue to use this site, you consent to our use of cookies.