WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I've added some content to WP's editor, however the new content does not respond to the click behaviour. Here's how I've added the content:

add_filter( 'default_content', 'custom_editor_content' );

Then created my function custom_editor_content:

function custom_editor_content( $content ) 

$content = '

<button id="test">Add</button>


echo $content;


The content is displayed within the editor ok, but it doesn't respond to the jQuery that's being loaded like:

add_action( 'admin_menu', array( $this, 'fnEnqueueAdminScripts' ) );

The js loads ok, so does the content, but I cannot understand why the click function doesn't work. Here's my js:

$( "#test" ).click(function() {

    alert( "Test" );


Other snippets of js in the same file does work. The problem seems to be with the click function. The content is not generated dynamically so I don't think is a question of using on such as

$("#test").on("click", function() {



Any ideas of what I've done wrong?

share|improve this question
Have you seen this? – toscho Aug 26 '13 at 21:59
default_content should return its value, not echo, otherwise the content will not be within the editor. – Milo Aug 26 '13 at 22:36
@tosho - yes, I did check whether the issue was related to non-conflict jQuery, so I did try both ways (using $ and jQuery), but the problem persists. – WagnerMatosUK Aug 27 '13 at 10:19
@Milo - I did change to return, however it didn't affect the jQuery situation - still doesn't work. any more suggestions? – WagnerMatosUK Aug 27 '13 at 10:20
I would guess that you'll have to make this work via the TinyMCE API, when the page loads the editor doesn't yet exist, and when it does get initialized it's within an iframe, so can't be targeted with a simple selector. – Milo Aug 27 '13 at 14:08
up vote 2 down vote accepted

Your jQuery code is using the $ symbol without accounting for noConflict mode.

More information: http://codex.wordpress.org/Function_Reference/wp_enqueue_script#jQuery_noConflict_Wrappers

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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