1

I need my frontend wp_editor() to not convert backticks into code automatically. I have checked the settings config in the tiny_mce_before_init filter as well as the documentation on the TinyMCE website and just can't find it. Current default behaviour means text wrapped inside backticks (``) is converted into a <code></code> block automatically and I don't want that.

  • Line 82 - 84 of wp-includes/js/tinymce/plugins/wptextpattern/plugin.js Is what causes this to happen, does anyone know of a way to disable it without modifying core WP Code? You can comment this out and it will stop but I want a more fault-tolerant way of doing it so that updating core doesn't wipe your change out. – Nicholas Koskowski Jun 15 '18 at 19:46
  • Why not just use the HTML entity for the backtick &#96;? – Justin R. Jun 15 '18 at 22:34
  • Thanks mate you've actually pointed me in the right direction. I know what I'm looking for now. Seems we can remove the inline action or disable that plugin entirely so it doesn't change any content on the fly. – Richard Webster Jun 15 '18 at 23:17
1

This has solved the problem, simply remove the plugin which automatically formats text as you type, from loading in the first place.

add_filter( 'tiny_mce_plugins', 'rwebster_editor_remove_wptextpattern', 1, 99 );
function rwebster_editor_remove_wptextpattern( $plugins ) {
    $wptextpattern = array_search( 'wptextpattern', $plugins );
    unset( $plugins[$wptextpattern] );
    return $plugins;
}
  • You should be aware that the plugin probably does more than just that (I also find it annoying that someone above decided what certain things mean with zero configuration options, at least right now) – Mark Kaplun Jun 16 '18 at 12:41
  • It's purely for changing formatting as you type. Code backticks, headings, lists. You can add extra ones to it as well. For completeness I'll probably update my answer to include removing specific things as well. All documented here: github.com/WordPress/WordPress/blob/master/wp-includes/js/… – Richard Webster Jun 16 '18 at 13:09
  • 1
    exactly, "purely changing the format", while might be something you do not need, might also be something that other people depend on in their writing flow, so this solution is good for people that do not depend on those goodies, but will be more problematic for those that do – Mark Kaplun Jun 16 '18 at 13:26
  • Yep I'll make some nice edits later, running on 4 hours #Naptime – Richard Webster Jun 16 '18 at 14:37
  • another comment, reading the question more carefully, is that if you need this only for front end editor, you should add the filter only when it is going to be displayed, and not "globally" – Mark Kaplun Jun 16 '18 at 14:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.