0

I would like to add some jQuery to wordpress/woocommerce admin page. The code works good on the client page but never pass to wp-admin page.

This is the code:

 jQuery("#postbox-container-1").ready(function(){
      alert("now what?");
        
      $('p:contains("Poivre")').css('color', 'red');
     
    });
disinfor
  • 10,865
  • 2
  • 33
  • 44
alduxo
  • 29
  • 7
  • You need to enqueue the script on the admin section. `add_action( 'admin_enqueue_scripts', 'your_enqueue_function' );` – disinfor Mar 26 '21 at 20:57
  • Does this answer your question? [How to add custom javascript to WordPress Admin?](https://stackoverflow.com/questions/3326967/how-to-add-custom-javascript-to-wordpress-admin) – disinfor Mar 26 '21 at 20:58
  • i used the following code but it did not work ... `add_action( 'admin_enqueue_scripts', jQuery("#postbox-container-1").ready(function(){ $('p:contains("Poivre")').css('color', 'red'); }));` still not getting it... – alduxo Mar 26 '21 at 21:31
  • That's not how enqueuing scripts work. You need to pass in a php function. Read the duplicate link. – disinfor Mar 26 '21 at 21:48

1 Answers1

0

You can use WP admin_footer action hook to add custom js to the admin side. check below code. code will go in the active theme functions.php file.

function add_custom_admin_js(){
    ?>
    <script type="text/javascript">
        (function($){
            $("#postbox-container-1").ready(function(){
                alert("now what?");  
                $('p:contains("Poivre")').css('color', 'red');
            });
        })(jQuery);
    </script>
    <?php
}

add_action( 'admin_footer', 'add_custom_admin_js', 10, 1 );
Bhautik
  • 11,125
  • 3
  • 16
  • 38
  • Welcome... If this answer helps you then you can [accept](https://stackoverflow.com/help/someone-answers) the answer, and if you like/want you can also [upvote](https://stackoverflow.com/help/someone-answers) the answer too, Thanks. – Bhautik Mar 27 '21 at 12:55