492 posts
  • Has sold $10,000+ on Envato Market
  • Has been part of the Envato Community for over 2 years
  • Sells items exclusively on Envato Market
  • Won a Most Wanted contest
+3 more
rayoflightt says

I have WordPress theme soft rejected because of problem with including jQuery in it. Message from reviewer is this: “Please use proper hooks to enqueue any scripts / styles i.e.: – wp_enqueue_scripts for frontend – login_enqueue_scripts for login screen – admin_enqueue_scripts for admin dashboard “

Last time I got the same message and I had this in functions.php:

add_action(‘admin_init’, ‘register_admin_scripts’); function register_admin_scripts() { wp_enqueue_script( ‘metaupload’, get_template_directory_uri() . ’/admin/assets/js/metaupload.js’ ); } add_action( ‘admin_enqueue_scripts’, ‘register_admin_scripts’ );

function its_scripts() { wp_enqueue_style( ‘style’, get_stylesheet_uri() );

wp_enqueue_script( ‘jquery’); wp_enqueue_script( ‘bootstrap’, get_template_directory_uri() . ’/assets/js/bootstrap.js’, array(‘jquery’), ‘1.0.0’, true ); wp_enqueue_script( ‘masonry’, get_template_directory_uri() . ’/assets/js/masonry.js’, array(‘jquery’), ‘1.0.0’, true, ‘1.0.0’, true ); wp_enqueue_script( ‘parallax’, get_template_directory_uri() . ’/assets/js/jquery.parallax-1.1.3.js’, array(‘jquery’), ‘1.0.0’, true ); wp_enqueue_script( ‘retina’, get_template_directory_uri() . ’/assets/js/retina.js’, array(‘jquery’), ‘1.0.0’, true ); wp_enqueue_script( ‘scripts’, get_template_directory_uri() . ’/assets/js/scripts.js’, array(‘jquery’), ‘1.0.0’, true ); } add_action( ‘wp_enqueue_scripts’, ‘its_scripts’ );

What is the right way to include jQuery in WordPress?

149 posts
  • Has referred 1+ members
  • Has sold $5,000+ on Envato Market
  • Has been a beta tester for an Envato feature
  • Has collected 10+ items on Envato Market
+3 more
davidossahdez says

Are you sure that the problem is with jQuery? You are including it correctly. I think that the mistake is in the first line. You are registering the admin scripts with the admin_init hook. The proper hook to enqueue any scripts in the admin is admin_enqueue_scripts

function register_admin_scripts() {
    wp_enqueue_script( 'metaupload', get_template_directory_uri() . '/admin/assets/js/metaupload.js' );
}
add_action( 'admin_enqueue_scripts', 'register_admin_scripts' );

function its_scripts() {
    wp_enqueue_style( 'style', get_stylesheet_uri() );
    wp_enqueue_script( 'jquery' );
    wp_enqueue_script( 'bootstrap', get_template_directory_uri() . '/assets/js/bootstrap.js', array( 'jquery' ), '1.0', true );
    wp_enqueue_script( 'masonry', get_template_directory_uri() . '/assets/js/masonry.js', array( 'jquery' ), '1.0', true );
    wp_enqueue_script( 'parallax', get_template_directory_uri() . '/assets/js/jquery.parallax-1.1.3.js', array( 'jquery' ), '1.0', true );
    wp_enqueue_script( 'retina', get_template_directory_uri() . '/assets/js/retina.js', array( 'jquery' ), '1.0', true );
    wp_enqueue_script( 'scripts', get_template_directory_uri() . '/assets/js/scripts.js', array( 'jquery' ), '1.0', true );
}
add_action( 'wp_enqueue_scripts', 'its_scripts' );
492 posts
  • Has sold $10,000+ on Envato Market
  • Has been part of the Envato Community for over 2 years
  • Sells items exclusively on Envato Market
  • Won a Most Wanted contest
+3 more
rayoflightt says

Hmm last time when I was checking it wasn’t working without admin_init hook but now it works. Thanks. :)

There is one more thing, including google fonts in theme. I have this in functions.php:

add_action(‘init’, ‘load_fonts’); function load_fonts() { wp_register_style(‘googleFonts’, ‘http://fonts.googleapis.com/css?family=PT+Sans:400,400italic,700,700italic'); wp_enqueue_style( ‘googleFonts’); } add_action(‘wp_enqueue_styles’, ‘load_fonts’);

and it won’t work with admin_init hook I just checked. Is this correct way for including google fonts?

1353 posts How's the surf doing?
  • Has referred 200+ members
  • Has sold $500,000+ on Envato Market
  • Has been a beta tester for an Envato feature
  • Has collected 10+ items on Envato Market
+6 more
tommusrhodus says
by
by
by
by
by
by