Articles of wp register script

jQuery plugin not loading

I am trying to use the below function to enquue 2 scripts (one internal, one external). The internal one (‘custom_script’) is working, but the 2nd one (‘formValidation’) isn’t (I get a ‘validate() is not a function’ error). The validation one is an external link to the script. Am I doing it wrong? If so, what’s […]

How to register script with null value for version?

Can someone explain the version argument in wp_register_script()? According to the codex it is added to the URL as a query string for cache busting purposes. It also says if the $ver argument is set to null, no version is added and if false, the currently installed version of WordPress is added. How do I […]

When to use add_action when registering/enqueuing scripts

When should you use add_action to enqueue or register a script, vs just using wp_register_script and/or wp_enqueue_script? In other words, both example 1 and example 2 below seem to accomplish the same thing when in functions.php, so why do so many resources say that example 1 is the correct way of loading scripts in WP? […]

Add crossorigin to SCRIPT tag

Is there any way to add a crossorigin attribute to a custom registered JavaScript? wp_register_script(‘foo’, ‘http://cdn.domain.com/script.min.js’, null, ‘1.2.3’); wp_enqueue_script( ‘bar’, ‘/path/to/bar.js’, array( ‘foo’ ), ‘20170912’ );

Register and enqueue style.css custom theme

I’m trying to create a custom theme for wordpress, I created all these file: style.css index.php function.php footer.php header.php page.php single.php front-page.php This is the code of my style.css: /* Theme name: La Pizzeria Theme URI: http://www.matteoschiatti.it Author: Matteo Schiatti Author URI: http://www.matteoschiatti.it Description: Theme for Restaurants Version: 1.0 License: GNU General Public License v2 […]

How to register and set http/2 server prefetch for a specific asset?

I have been using, this plugin and its says WordPress 4.6 introduced native support for resource hints. By default, this plugin defers to WordPress 4.6 and theme/plugin developers to responsibly prefetch the right assets. Sites running on older versions of WordPress will continue to get the previous behavior where all JavaScript and stylesheets had resource […]

admin_enqueue_scripts not rending JS file correctly

I’ll keep this short and sweet, I want to load a JS file in the admin panel as part of my plugin, and through tons of research I have a few different options that have all ended with the same problem that no one else seems to be experiencing so finally I’m posting for a […]

Register google jquery gets overwritten by plugin

I’m currently using a plugin, which includes jquery version 1.6.4 like this: function thethe_image_slider_head_scripts(){ wp_deregister_script( ‘jquery’ ); wp_register_script( ‘jquery’, ‘https://ajax.googleapis.com/ajax/libs/jquery/1.6.4/ jquery.min.js’, false, ‘latest’); wp_enqueue_script( ‘jquery’ ); wp_enqueue_script(‘slider-ui’, THETHE_IMAGE_SLIDER_URL.’style/js/thethe-image-slider.js’, array(‘jquery’)); } The problem is, I’m deregistering jquery in my functions.php file within my theme, to get version 1.7.2. But it still takes the version 1.6.4.. I […]

include jquery plugin file not working

My code for include js as follows: function you_fancy_js(){ wp_register_script( ‘custom-script’, plugins_url( ‘/js/jquery.js’, __FILE__ ), array( ‘jquery’, ‘jquery-ui-1.8.18.custom.min’, ‘jquery.validate.min’ ) ); wp_enqueue_script( ‘custom-script’ ); } add_action(‘wp_enqueue_scripts’,’you_fancy_js’); add_action(‘admin_head’,’you_fancy_js’); The above code should include a js file. It is not working.

If a Script has been enqueued but not registered can I still removed it?

There is a plugin that’s conflicting with mine when the user loads the admin pages of my plugin, therefore I want to deregister and remove the conflicting script on these pages. Here is the code for the conflicting script:- add_action( ‘admin_head’, ‘function_name’ ); function function_name() { if ( is_admin() ) { wp_enqueue_script( ‘script_name’, plugins_url(‘/js/some_javascript_file.js’, __FILE__ […]