Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

128
Views
Wordpress - Adding custom media button to editor not working. Event listener is not catching click

Hi I am trying to do a button for user to insert a template of shortcode like [commit_shortcode commit_ids=""]. To achieve that I created a button next to Add Media button, called Add Commit Lists. enter image description here

But apparently click on it does not firing an event to catch and execute js script.

How I am adding a button and js script for it:

        add_action('media_buttons', function() {
            echo '<button type="button" id="insert-my-commits" class="button insert-my-commits">Add Commit List</button>';
        }, 100);

        add_action( 'wp_enqueue_media', function (){
            wp_enqueue_script('media_button',
                OWD_VCS_MANAGER_PLUGIN_URL . 'assets/js/addCommitListButton.js',
                ['jquery'],
                '1.0.0',
                true);
        }, 100);

And my js script for handling adding a shortcode to editor:

jQuery( function( $ ) {
    $( '.insert-my-commits' ).click( openMediaWindow );

    console.log('It is working here');
    
    acf.addAction( 'load', function() {
        $( '.insert-my-commits' ).on( 'click', function() {

            console.log('It is NEVER working here');
            
            openMediaWindow();
        } );
    } );

    function openMediaWindow() {
            wp.media.editor.insert('[commit_shortcode commit_ids=""]');
    }
} );

It looks like something is catching click event and stopping my script from execution. If anyone has an idea I would be greatly thank you. Also I was using this tutorial: https://www.sitepoint.com/adding-a-media-button-to-the-content-editor/

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!