Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

Questions tagged [wp-register-script]

With `wp_register_script` it is possible to make WP aware of a script without actually loading it. It can later be loaded with `wp_enqueue_script`, but will also automatically load when another script is enqueued that depends on that script.

0
votes
1answer
23 views

Why is Wordpress enqueuing admin relevant scripts (e.g., React, ReactDOM, Redux, hooks, TinyMCE etc) when not logged in?

In attempting to boost the performance of my website, I've noticed that Wordpress is enqueuing a lot of the admin relevant scripts and stylesheets on the front end. I'm wondering how I can stop this ...
0
votes
2answers
25 views

Wordpress error when replacing local jQuery by externally-hosted

I'm trying to load jquery from CDN instead of loading natively with wordpress. In my functions.php I have done it like below, making sure it should only happen on the front-end: function ...
0
votes
0answers
15 views

plugins_url not returning correct directory

This plugin works on my live wordpress instance. However, on my local machine, none of the javascript is getting triggered. I think it has to do with plugins_url and it most likely not returning the ...
0
votes
1answer
18 views

When to use wp_register_script() function?

When I came to know the function wp_register_script(), I had some questions came to my mind: Should I register each script first and then enqueue it? And is this a best practice? Or, Should I ...
0
votes
2answers
204 views

Enqueuing script is adding extra text for google maps [closed]

I'm setting up a google map on my site and I'm trying to set the enqueue my scripts up but am getting an error: I have placed this code in my functions.php (actual api key not used here): function ...
0
votes
0answers
17 views

wp_register_script was called incorrectly file location

So I took over a site with 100+ plugins. I've reduced the plugin stack to 44. With WP_DEBUG enabled; I am getting a wp_register_script was called incorrectly warning. Is there an easy way to find ...
0
votes
1answer
65 views

Starting with tabbed metabox

I need a tabbed metabox for my plugin. Actually they are 5 metaboxes each one in a tab. I found these scripts: https://speckyboy.com/10-simple-code-snippets-creating-beautiful-tabs/ Which one is ...
0
votes
0answers
33 views

How do I keep children of certain parent menus expanded by default on a sidebar?

We are using advanced sidebar pages menu: https://wordpress.org/plugins/advanced-sidebar-menu/ to expand / collapse children menus on a sidebar. By default, the parent sidebar menu is expanded, ...
0
votes
1answer
39 views

How to call wp_localize_script() after the script?

I am trying to use the WordPress path URL in my js script file. I read here that I need to use wp_localize_script. But, I according to Codex's documentation wp_localize_script() MUST be called ...
0
votes
1answer
45 views

How to use wp_register_script / wp_enqueue_script for multiple queries

I have a wp_register_script / wp_enqueue_script and need to reuse this for multiple states, how do I do this? This is the code: wp_register_script( 'scount', get_template_directory_uri() . '/...
2
votes
1answer
26 views

Can't get JS code to work with shortcode

I am trying to create a plugin and I've got stuck. I am trying to register and enqueue a script from a shortcode: This is my shortcode: add_shortcode( 'gear-guide', 'gg_product_front_end' ); This ...
1
vote
1answer
40 views

Why won't my scripts load?

I am having trouble loading scripts in functions.php I've done this before so I'm sure I'm overlooking something but as far as I can tell it is correct and I have tried copying and pasting from other ...
0
votes
0answers
13 views

How to set multiple user role in single registration page

This is a login/register page of jobroller theme. I want same login/register page with wordpress twenty-sixteen theme. I am kinda noob in this. How can i do this without using the jobroller theme?
0
votes
1answer
70 views

bundled jquery in theme js not working with wp_localize_script

I've bundled jquery in my theme js using grunt-uglify. Now I want to prevent wp jquery from loading since I don't need 2 jquery versions and want to save unnecessary requests. This is what I have: ...
0
votes
1answer
32 views

How to redirect new registrars to a custom registration page instead of WP default registration page?

How to redirect the user from this page domain.com/wp-login.php/action=register to another page?
0
votes
1answer
30 views

Tell WP register script to load a script only when the entire page is loaded

When not in WordPress we can tell a script to load when the entire page has loaded like this : $(window).bind("load", function() { // code here }); But is this achievable through this function (...
1
vote
1answer
258 views

Adding multiple wp_register_scripts for templates in WordPres?

How do I add multiple JavaScript files to templates? The below works great for only ONE Javascript file which loads on the templates called template-1.php and template-2.php - but I have another 3 ...
0
votes
1answer
364 views

Use js script from one plugin in another plugin

I have two plugins that work together (one is an add-on of sorts). In the "main" plugin, I have a js function in a file located like so: wp-plugins/main-plugin-name/js/main-js.js If my secondary ...
0
votes
2answers
379 views

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 ...
2
votes
3answers
283 views

wp_register_script multiple identifiers?

In order to avoid poor performance with multiple <script> tags I do concatenation of scripts regularly and produce one single bundle.min.js JS file and 'jsbundle' identifier. Problem is, things ...
0
votes
1answer
334 views

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....
0
votes
1answer
389 views

JavaScript file successfully registered but does not render correctly

I have this page that uses colorbox to popup information about the staff members when the photo is clicked. My page is a child theme of a West and I inserted the following code in the functions.php /...
1
vote
2answers
38 views

Registering a script dilemma→ wp_register_script

wp_register_script( $handle, $src, $deps, $ver, $in_footer ); If $ver is not required then should we leave that space blank? or completely remove the commas? Example → wp_register_script( 'scroll', ...
0
votes
2answers
461 views

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/...
0
votes
2answers
438 views

Adding JS in header when using wp_enqueue_script in a shortcode

I'm trying to enqueue a JavaScript file in the header of my website. If I add the following in my main plugin file the JS is included in the header: function wpdocs_theme_name_scripts() { ...
1
vote
1answer
565 views

Best spot for wp_register_script() and wp_register_style()

I need to enqueue multiple scripts and styles in my plugin. However, I do not like the idea of calling wp_register_script() and wp_register_style() every time I need to call wp_enqueue_script() and ...
2
votes
1answer
735 views

Can't move jQuery to footer

Below two methods did not help me. My jQuery is always on the head section. What can be the reason? Method 1: (adding below code to function.php) if (!is_admin()) add_action("wp_enqueue_scripts", "...
1
vote
1answer
1k views

WP .js script file not loading

I have looked all over the place and did not find a solution to my problem. I have a child theme where I have a functions.php file where I try to register and enqueue the script the following way: ...
0
votes
3answers
632 views

Scripts not loading through function Method in Wordpress Theme

I am trying to load CSS and Javscripts through the functions. CSS are loading, but dont know what mistake has been done that javascripts and Jquery are not loading through the functions method. I ...
5
votes
1answer
4k views

Cannot deregister a script using wp_deregister_script

I am trying to get rig of the Disqus script on my front page, but unfortunately I cannot manage how to do this. Here is a little story of the steps I've done. Find the script name in the source code ...
1
vote
1answer
101 views

Pass $this to function nested in another public function of the same class

I'm building a plugin using the WordPress Plugin Boilerplate by DevinVinson. I'm adding a public shortcode function for wich I will need some resources (js and css), I want to enqueue scripts (that ...
0
votes
2answers
245 views

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 ...
5
votes
2answers
2k views

Enqueue script only when shortcode is used, with WP Plugin Boilerplate

I'm building a plugin using the WordPress Plugin Boilerplate by DevinVinson. Everything works fine, except one thing: I'm trying to enqueue scripts and css only when a shortcode is present in the ...
3
votes
1answer
898 views

Adding jQuery dependency prevents my script from enqueuing/loading

This works: add_action('wp_enqueue_scripts', 'custom_script_enqueue'); function custom_script_enqueue() { wp_enqueue_style( 'customstyle', get_template_directory_uri() . '/css/theme....
0
votes
1answer
333 views

Remove snippets of JS from core

I can see these bits of code in the source in my wp install: <!-- jQuery --> <script type="text/html" id="tmpl-wp-playlist-current-item"> <# if ( data.image ) { #> <img ...
0
votes
1answer
66 views

True parameter but jquery register in header and not in the footer with wp_register_script

I want to register jquery.js in the footer, but even with the true parameter it registers in the header. Here is the code. The other scripts are registered in the footer. Only jquery does not. ...
0
votes
1answer
51 views

How to get, in WP page's script, a wp enqueued script (in Functions.php)?

I’m very new to WP, and to JS as well, and need to do a simple change to existing code, so forgive my ignorance… For getting the current User Id I followed examples and added an action + function to ...
0
votes
1answer
202 views

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 ...
0
votes
1answer
3k views

wp_enqueue_scripts does not work

I am creating a theme for Wordpress, but the wp_enqueue_scripts does not work. The code that is in functions.php is: <?php function scripts_and_styles() { if ( ! is_admin() ) { ...
2
votes
1answer
247 views

Register script version not showing

I want to implement cache busting on a specific script, but the version is not added to the url as query vars. Here is the code I'm using : wp_register_script( 'custom', ...
1
vote
1answer
131 views

How to cancel `wp_print_scripts`?

I want to load all the scripts in $wp_scripts with my own JS function after the window.onload event. Is there a simple way to prevent wp_print_scripts from printing the default list of <script> ...
0
votes
1answer
869 views

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 ...
1
vote
1answer
1k views

wp_register_script(… $in_footer = true) not working

I'd like to load some javascript files in my footer. I tried to accomplish it in functions.php like so: function my_init() { // LOAD JQUERY wp_deregister_script('jquery'); ...
1
vote
1answer
458 views

Where does WordPress register default scripts like jQuery?

I'm figuring out the ins and outs of WordPress. I know that WordPress sets some default filters and actions in /wp-includes/default-filters.php, but where does it register its scripts like jQuery? We ...
-1
votes
1answer
455 views

How to make a customized user registration form using the built in wp-register() template tag

I want to make a registration form in WordPress, but i need it to contain my own custom input fields. For instance, i need it to have an input field such as COUNTRY, SCHOOL, COURSE, YEAR_OF_ADMISSION,...
2
votes
1answer
2k views

wp_enqueue_script with dependencies doesn't work

I'm having this code: wp_register_script('parent','parent.js', array('child'), '1', true); wp_register_script('child', 'child.js', array('grandchild'), '1', true); wp_register_script('grandchild', '...
1
vote
3answers
1k views

Loading scripts with wp_register_script and wp_enqueue_script

How could I include the following script and stylesheet in a wordpress plugin if they only need to load in the admin panel? <script type="text/javascript" src="/wp-includes/js/jquery/jquery.js?ver=...
0
votes
3answers
1k views

Using wp_enqueue_script on scripts that contain PHP

I'm am working on a WooCommerce website, and have all my jQuery in the footer inside script tags. I use PHP to filter out the needed scripts for any particular page. However, I would like to use the ...
1
vote
3answers
2k views

WordPress script file version numbers changing in live environment

I'm registering my javascript files for Wordpress in my functions file as so: if( !function_exists( "theme_js" ) ) { function theme_js(){ wp_register_script('wpbs-scripts', ...
0
votes
1answer
59 views

How should I go about registering JavaScript that isn't a file? [duplicate]

For a plugin I'm creating it generates custom JavaScript that should be executed in the footer of the page. Being that it's custom JavaScript, I can't simply put it in a file and register & ...