Title: Problem with Widget and Code Editor API
Last modified: November 16, 2017

---

# Problem with Widget and Code Editor API

 *  [Giulio](https://wordpress.org/support/users/ferocious/)
 * (@ferocious)
 * [8 years, 6 months ago](https://wordpress.org/support/topic/problem-with-widget-and-code-editor-api/)
 * Hello!
 * Wordpress 4.9 introduces CodeMirror library for use within core and an API to
   use with plugin development. I was able to successfully manage how to integrate
   the editor into the administration page of my plugin following [Ruter’s advice](https://make.wordpress.org/core/2017/10/22/code-editing-improvements-in-wordpress-4-9/)
   in his post but when I come to face with Widget API I can not handle this new
   feature because I don’t know the Widget ID to pass as parameter to `wp.codeEditor.
   initialize()`.
    Before the 4.9 release I used a copy of `custom-html-widgets.
   js` adapted for use by my plugin but now it does not work anymore. What is the
   correct way to use CodeMirror with the Widget API?

Viewing 1 replies (of 1 total)

 *  Thread Starter [Giulio](https://wordpress.org/support/users/ferocious/)
 * (@ferocious)
 * [8 years, 6 months ago](https://wordpress.org/support/topic/problem-with-widget-and-code-editor-api/#post-9698482)
 * I don’t like answering my own question, but I feel this is the one of the possible
   solutions so far, but not the best:
    I used the file `custom-html-widgets.js`
   as a model for my own plugin, renaming the main method to avoid conflicts to 
   runtime. Each plugin needs this file in order to use Codemirror into the Widgets
   panel and connecting it directly by using `wp_enqueue_script` does not seem to
   work. Then I worked on `InitializeEditor` and `Init` in order to find the selector
   for the textarea of my widget. At last I did register this new script with wp_register_script
   in the Widget extended class.

Viewing 1 replies (of 1 total)

The topic ‘Problem with Widget and Code Editor API’ is closed to new replies.

## Tags

 * [codemirror](https://wordpress.org/support/topic-tag/codemirror/)
 * [javascript](https://wordpress.org/support/topic-tag/javascript/)
 * [widget](https://wordpress.org/support/topic-tag/widget/)

 * In: [Developing with WordPress](https://wordpress.org/support/forum/wp-advanced/)
 * 1 reply
 * 1 participant
 * Last reply from: [Giulio](https://wordpress.org/support/users/ferocious/)
 * Last activity: [8 years, 6 months ago](https://wordpress.org/support/topic/problem-with-widget-and-code-editor-api/#post-9698482)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
