520 posts
  • Has sold $10,000+ on Envato Market
  • Has been part of the Envato Community for over 3 years
  • Sells items exclusively on Envato Market
  • Won a Most Wanted contest
+2 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' );
520 posts
  • Has sold $10,000+ on Envato Market
  • Has been part of the Envato Community for over 3 years
  • Sells items exclusively on Envato Market
  • Won a Most Wanted contest
+2 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?

1585 posts How's the surf doing?
  • Elite Author: Sold more than $75,000 on Envato Market
  • Has been part of the Envato Community for over 3 years
  • Had an item featured on Envato Market
  • Made it to the Authors' Hall of Fame
+6 more
tommusrhodus says

Helpful Information

  • Please read our community guidelines. Self promotion and discussion of piracy is not allowed.
  • Open a support ticket if you would like specific help with your account, deposits or purchases.
  • Item Support by authors is optional and may vary. Please see the Support tab on each item page.

Most of all, enjoy your time here. Thank you for being a valued Envato community member.

Post Reply

Format your entry with some basic HTML. Read the Full Details, or here is a refresher:

<strong></strong> to make things bold
<em></em> to emphasize
<ul><li> or <ol><li> to make lists
<h3> or <h4> to make headings
<pre></pre> for code blocks
<code></code> for a few words of code
<a></a> for links
<img> to paste in an image (it'll need to be hosted somewhere else though)
<blockquote></blockquote> to quote somebody

:grin: :shocked: :cry: Complete List of Smiley Codes

by
by
by
by
by
by