Home » Jquery » php – Using jQuery on WordPress

php – Using jQuery on WordPress

Posted by: admin February 22, 2020 Leave a comment

Questions:

This is my first ever experience with jQuery. My code to load in the jQuery is:

function load_sitekit_jquery ($hook) {
    //if( 'admin.php' != $hook )
       // return;
    wp_enqueue_script( 'sitekit', plugins_url('assets/sitekit.js', __FILE__) );
}
add_action( 'admin_enqueue_scripts', 'load_sitekit_jquery' );

The script itself:

jQuery(document).ready(function($) {
  $( "div:contains('PageSpeed Insights')" ).css( "display", "none" );
})

What am I doing wrong?

How to&Answer:

I think you need enqueue the jQuery inorder to use that. Please find the below code and replace your one with it.

function load_sitekit_jquery ($hook) {
    //if( 'admin.php' != $hook )
       // return;
    wp_enqueue_script( 'sitekit', plugins_url('assets/sitekit.js', __FILE__),array('jquery') );
}
add_action( 'admin_enqueue_scripts', 'load_sitekit_jquery' ); 

Hope that will work for you.