

If you want to get the URL to a script/stylesheet in your theme, simply use get_template_directory_url(). Plugins_url() has been included to point to the location of script or style we desire to enqueue. You will use the same action hook wp_enqueue_scripts for registering/enqueuing both styles and scripts.
WP ENQUEUE SCRIPT WAS CALLED INCORRECTLY WORDPRESS CODE
You may go through the following sample of code (you should add the code into the functions.php file of your current WordPress theme, e.g.: /public_html/wp-content/themes/theme-name-here/functions.php): Similar to scripts, one can easily enqueue stylesheets.

Going with this extra step for registering followed by enqueuing the script will allow other plugins/themes to deregister your script without modifying the core code of plug-in.

In case of header, the value must be set to false.Īfter providing all parameters in wp_register_script(), call the wp_enqueue_script() to actually enqueue the registered script by it’s handle. $in_footer – In order to load script into the footer section, it is good to set the value to be true.$ver – ver stands for version number of the script.Since the script mentioned above uses jQuery, jQuery has been mentioned in the dependency area. The plugins_url() function is taken into usage to get the proper URL of plugins folder. $src – scr refers to the location of script.$handle – It is the unique name provided to script.This particular function is well known to accept the following parameters: The procedure started by simply registering the script with the help of wp_register_script() function. You may take into usage the following code for loading of scripts in WordPress (you should add the code into the functions.php file of your current WordPress theme, e.g.: /public_html/wp-content/themes/theme-name-here/functions.php): It is an easy task to enqueue the scripts in WordPress in a proper manner. It also helps in reducing the load time of page along with avoiding easy conflicts with themes and plug-ins.Įnqueuing scripts in WordPress also ensures that duplicates with the same handle are not loaded twice.Īlways use wp_enqueue_script to load JavaScript files in WordPress. Such a feature allows everybody to utilize the built-in JavaScript libraries that come in a bundled form. With the help of the wp_enqueue_script() function, you can easily inform WordPress the best time to load a script long with dependencies if any. This particular function provides a systematic way of loading JavaScript along with styles. To ensure that everything works properly and that one plugin or theme doesn’t break another, WordPress has an enqueue script function. Thousands of people all around the world design themes and plugins for WordPress. WordPress has a large and strong developer community. Assuming that other plugins will use this jQuery distributed with WordPress, loading a different, custom version will only result in problems. WordPress comes packaged with it’s own version of jQuery which should be used. In case you load jQuery manually along with another plugin that already uses jQuery, it will be loaded twice, resulting in JavaScript errors.Īnother common mistake that plugin and theme developers make is that they load their own, custom version of jQuery which is not recommended. Though easy, it is a wrong way of adding scripts in WordPress.

Guys who are not familiar, simply add their scripts through the following code: WordPress has a wp_head() function with a wp_head action hook that enables you to load anything into the head section of the website. It is important to enqueue scripts and styles correctly in WordPress. It is high time to get an overview regarding the best way of enqueuing scripts along with styles in WordPress. This article is useful to any WordPress developer who is creating a WordPress plugin or theme to know what the best practise of enqueuing scripts/styles is. WordPress has an enqueuing system for adding local/remote scripts along with styles to prevent conflicts with plug-ins. Since most users run WordPress with a theme and several plugins, developers are advised to use the correct method of loading scripts into WordPress. I already checked that.Enqueue scripts and styles in WordPress the correct way. Line 2944 is just the line that throws an error. (This message was added in version 3.3.) in C:\xampp\htdocs\wp-includes\functions.php on line 2944 Please see Debugging in WordPress for more information. Scripts and styles should not be registered or enqueued until the wp_enqueue_scripts, admin_enqueue_scripts, or init hooks. I debugged and this is the error: Notice: wp_enqueue_script was called incorrectly.
