Podcast #128: We chat with Kent C Dodds about why he loves React and discuss what life was like in the dark days before Git. Listen now.

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.

Filter by
Sorted by
Tagged with
3
votes
1answer
29 views

enqueuing React script and hooking its target div fails to load script

I am getting a silent failure on the below code as I try to enqueue a static React.js script and hook its injecting div into the admin_footer. I see the page and my test echo plus the url of the ...
1
vote
1answer
76 views

React JSX in Wordpress Plugin Development

I was able to get React working in my custom Wordpress Plugin but I forgot how I got it working. What I'm trying to do is use a react component I have in NPM and use it as a Wordpress plugin. I used ...
0
votes
0answers
39 views

Enqueue registered dependencies only when necessary

I'm developing plugin where I want to load my dependency JS libraries only when the setting is enabled. The most correct way is to register all the scripts and styles I have and then enqueue my main ...
1
vote
3answers
109 views

How to dequeue / deregister any theme styles and scripts

Is it possible to some how make my plugin dequeue / deregister any styles and any scripts from what ever theme activated. so it doesn't matter what theme will be installed the styles and scripts of ...
0
votes
2answers
146 views

Plugin Activation Causes wp_register errors

I've been making a find-a-dealer type plugin in WordPress and I finally got it all done, everything works on my local and dev server. I push it up to production and upon activation, I get these ...
1
vote
2answers
174 views

is_page() function doesnt working

I'm trying to add these custom CSS and JS (written inside a custom plugin) only add to a specific page. this is my code <?php function randomAlphaNumeric($length) { $pool = array_merge(...
0
votes
1answer
26 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
59 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
21 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
20 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
455 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
150 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
60 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
135 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
78 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
51 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
1answer
113 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
35 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
46 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
338 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
494 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
529 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
436 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
478 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
445 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
551 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
589 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
847 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
836 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
911 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
5k 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
139 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
439 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 ...
4
votes
2answers
3k 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 ...
2
votes
1answer
1k 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
359 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
76 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
54 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
248 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
310 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
168 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
925 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
542 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
584 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,...