Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

132
Vistas
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
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda