skip to Main Content

Add Syntax Highlighting to TinyMCE Text Mode for any Custom Post Type

TInyMCE has a nice function to switch between html and visual modes. Unfortunately the plain text mdoe with the HTML is not as beatiful as it could be. But there is help out there. Just install this plugin and give it a minor tweak to make it compatible with most other custom pst types. Unfortunately with it’s basic configuration it only supports posts and pages.

HTML Editor Syntax Highlighter

What is does it it adds syntax highlighting to the text mode of tinymce. We have to hardcode a minor change so that this does not only apply to pages and posts but also other post types. You can follow the discussion here: https://wordpress.org/support/topic/force-execution-for-custom-admin-pages/

To also have this functionality in our extension we need to open this file: /wp-content/plugins/html-editor-syntax-highlighter/html-editor-syntax-highlighter.php and change the according part over there:

public function __construct () {
  add_action( 'admin_init', array(&$this, 'hesh_set_options') );
  add_action( 'wp_ajax_'.$this->formProcessName, array(&$this, 'hesh_options_form_process'));

  // Load only on certain pages
  /* knowboard: force the highlighter on all pages not just these
  if (
    !strstr($_SERVER['SCRIPT_NAME'], 'post.php') && 
    !strstr($_SERVER['SCRIPT_NAME'], 'post-new.php') &&
    !strstr($_SERVER['SCRIPT_NAME'], 'editor.php')
  ) return;
  */
  add_action( 'admin_enqueue_scripts', array(&$this, 'hesh_admin_enqueue_scripts' ) );
  add_action( 'admin_footer', array(&$this, 'hesh_output_form') );
  add_action( 'admin_notices', array(&$this, 'display_survey_notice' ));
}

 

Schreibe einen Kommentar

Deine E-Mail-Adresse wird nicht veröffentlicht. Erforderliche Felder sind mit * markiert.

Back To Top