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 have added a custom button to the media actions in a custom theme,

function wp_myplugin_media_button($context) {
    $wp_myplugin_media_button_image = '../wp-content/themes/datamine/images/icon_create_table.gif';
    $wp_myplugin_media_button = ' %s' . '<a id="fluffyRabbit" href="javascript:;" title="Add a Tabletool table to the post.">  <img src="'.$wp_myplugin_media_button_image.'" alt="" /></a>'; // table.php?type=tabletool&amp;TB_iframe=true" class="thickbox"
    return sprintf($context, $wp_myplugin_media_button);

add_filter('media_buttons_context', 'wp_myplugin_media_button');

but how can I attach event listeners?

$('#fluffyRabbit').live('click',function() { alert('o hai!'); });

If I use add_action, do I have to include a new script.js file?

If someone can step by step me on this that would be awesome. I just started really tinkering with WP.

Cheers! Bo

share|improve this question

Where are you attaching this listener:

$('#fluffyRabbit').live('click',function() { alert('o hai!'); });

I suppose that if you attach within a

    //attach here 
    $('#fluffyRabbit').live('click',function() { alert('o hai!'); });

that would do the trick. Is it working for you?

share|improve this answer
OK does this get added in the main js? I tried adding it in the functions.php and in the header (both ways you stated above) it didnt work. I was looking for a best practices method/tutorial on adding jQuery to a theme. – roberthuttinger Mar 3 '12 at 21:29
you've to use jQuery instead of $ in wordpress – Mohit Bumb Sep 11 '12 at 4:10
up vote 0 down vote accepted

I got it to work after playing around for while...

this went in the custom js file

    jQuery('#fluffyRabbit').live('click',function() { console.log('o hai!'); });


this went in functions.php

function load_scripts() {
   wp_enqueue_script('ttcustom', '/wp-content/themes/twitunez/ttcustom.js', array('jquery'));

add_action('init', 'load_scripts');

share|improve this answer

Sorry I didn't got that you needed the wp_enqueue_script practice. I thought you were stuck on how to call bind your event. But you sorted out by yourself. That's the correct way to do it. You could also write the jQuery call in your footer.php in HTML. Not the cleanest but working still.

share|improve this answer
thanks for the followup! – roberthuttinger Mar 5 '12 at 14:19

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.