Questions tagged [wp-enqueue-script]

Links a script file to the generated page at the right time according to the script dependencies, if the script has not been already included and if all the dependencies have been registered. You could either link a script with a handle previously registered using the wp_register_script() function, or provide this function with all the parameters necessary to link a script. This is the recommended method of linking JavaScript to a WordPress generated page.

Filter by
Sorted by
Tagged with
1
vote
1answer
18 views

Register vendor JS/CSS only on pages that require them?

I have some JS \ CSS that is used within selected pages on my site for various UI functions, for example an image slider. This image slider is only used on a few pages inside the site and loading it ...
0
votes
0answers
12 views

Dequeue Parent Theme File and Enqueue Child's

Not being able to achieve this simple thing for some reason Parent Theme Code (File: css_js_include.php) if( 'estate_property' == get_post_type() || 'estate_agent' == get_post_type() || ...
0
votes
1answer
14 views

My scripts-bundle.js file is getting sent to the browser as a stylesheet css file. Help!

I'm new to WordPress custom theme development. I am using a child theme for OceanWP. I have a webpack setup to hot-reload my files but my js scripts are not getting sent to my WordPress site instead ...
0
votes
1answer
15 views

How do I get rid of my inclusion race-condition on wp_enqueue_script

I'm trying not to be a lazy dev. Thus I want to only include my js files where they are needed. As the js is needed everywhere where my shortcode is used I tried to do what was answered here. i.e.: ...
0
votes
1answer
16 views

Changing URL of scripts, scripts outside theme folder?

Is it possible to have css and js scripts outside of template directory? If it is possible, how can I achieve it? Basically, instead of having: http://example.com/wp-content/themes/mytheme/assets/...
0
votes
0answers
26 views

Why does my wp_enqueue_script() only insert the script for logged in users

I've got a really simple enqueue in my functions.php file. The weird thing is that it only actually inserts the script if I'm logged in. I've tried wiping out everything else in the functions.php but ...
1
vote
1answer
56 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
1answer
30 views

Dequeue Scripts and Style for Mobile not working?

I've followed a few tutorials on Dequeueing and Deregistering scripts and styles for WP - trying to optimise my site speed. Initially I could dequeue and deregister, until I added a condition for ...
0
votes
0answers
27 views

Override parent theme deregister

I have a parent theme that deregisters a script, in my case jquery. It does it like this: function parent_enqueue_scripts() { wp_deregister_script( 'jquery' ); [...] } However, in my child ...
0
votes
2answers
34 views

functions.php - inject inline css from file

I would like to read from a .css file and inject it as an inline style in wp_head. it's possible? i've tried this "Add inline css to theme" solution but it doesn't do what I expect because I expect ...
0
votes
0answers
23 views

Scripts don't enqueue after removing plugin

Using the Ultimate Member plugin. My custom scripts are loading in my child-theme as follows: function some_theme_enqueue_styles() { wp_enqueue_style( 'parent-style', get_template_directory_uri() ...
0
votes
0answers
35 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 ...
0
votes
2answers
59 views

How to execute Javascript on a Wordpress page?

I'm trying to get some Javascript to run on one of my pages. But nothing I do seems to work. I ran the code in a sandbox and it is functional. I tried: - Inserting and HTML builder element and ...
1
vote
3answers
49 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 ...
1
vote
1answer
46 views

wp_localize_script not working on ajax response

When a file is uploaded to my page I make an ajax call to add an entry in a database. I then want to send a string back to the client using wp_localize_script but when I try to access it I just get an ...
0
votes
1answer
20 views

Append php file to footer

I have javascript in my php file. and I want to load it in footer. Is any method for that?
1
vote
2answers
22 views

Exclude JS file from 404 error page

I have a custom tracking system in place which works with an include of a .js file in the footer of each page. Unfortunately some high traffic sites are including images from my site which are ...
1
vote
0answers
30 views

Stop WordPress editor embedding links

There are several posts about this, - but I suspect that it has changed after Gutenberg, since I can't get either of the methods to work. I'm trying to stop WordPress embedding links, when written ...
0
votes
0answers
19 views

How to avoid conflict if a plugin already have included open library?

I am trying to use the swiper the library. https://idangero.us/swiper/get-started/ But the Elementor plugin is already added that : https://github.com/elementor/elementor/tree/master/assets/lib/...
0
votes
0answers
36 views

jQuery UI with touchpunch not fully working on touch devices

I'm currently trying to get the jQuery UI sortable function working on my Android phone (touch). Sadly, the touch event don't works on my phone. I've tried everything. jQuery("#details-inner")....
0
votes
1answer
28 views

wp_enqueue_script add integrity parameter

I'm adding fontawesome script to my site, and I didn't found a proper way to add the fontawesome's integrity parameter (integrity="sha384-DJ25uNYET2XCl5ZF++...
0
votes
0answers
18 views

Scripts and stylesheets failing to load in Chrome IOS (and only Chrome IOS)

My script and stylesheet files have been failing to load in Chrome IOS, and only Chrome IOS. I changing the value of $ver in wp_register_script from a string with a value ("1.0.17") to an empty string,...
1
vote
2answers
136 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
27 views

AJAX call of function containing javascript which is not loaded (Plugin development)

I have written a plugin which has a usermanagement page in the backend. This page loads userdata from the database by an AJAX call. The data returned from this function does contain HTML with class ...
0
votes
1answer
95 views

Enqueue script with version number not working

I am trying to enqueue a script for a custom plugin and I want to include a version number for cache busting. However, the ?ver= query is not being appended to the script name in the html and ...
0
votes
0answers
29 views

Webpack 4: combine core and plugins in unique build/admin.js?

I'm going through @wordpress/scripts but it's not clear to me how to emit a unique 'build/output.js' which would combine / merge all the assets (admin and plugins) through webpack 4. Let me explain. ...
3
votes
2answers
109 views

Issue with using Underscore in Wordpress

I have read in another SO post that Underscore.js is including in Wordpress by default. I am using it to test if a variable is defined but get this in the browser console: pluginAdminPage.js:32 ...
0
votes
1answer
37 views

How to make JQuery load on top of head tag before everything

my website and plugins insert some jquery code between HTML tag and also whatever I do to insert jquery as a first script in the head section I can't get it to work I tried function ...
0
votes
1answer
28 views

How to enqueue a script on a specific URL that contains multiple parts

I've tried using is_page() to pass the URL to but the page I am trying to enqueue my script on is "races/community/add" and isn't a single slug like "about-us". Is it possible to do this with is_page()...
0
votes
2answers
40 views

Loading two versions of same JS libary

Currently migrating from an older version of a JS library (sweetAlerts), to a newer version. Both versions load, but I want to be able to use the updated library, but unsure how to reference it in ...
0
votes
1answer
24 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
1answer
81 views

How register library to use jquery correct

How register from my plugin level correct jquery? If i run this : function insertJQuery() { wp_deregister_script('jquery'); wp_enqueue_script('jquery', 'https://ajax....
0
votes
1answer
37 views

Enqueing External JS on the remote server JS

wp_register_script( 'custom-js', 'https://s3.amazonaws.com/codexo/custom.js', array( 'jquery' ), '1.1', true ); wp_enqueue_script( 'custom-js' ); Above is the function through which I am ...
0
votes
2answers
49 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
6 views

Printing extra scripts before src scripts to optimize minification and page speed

In WordPress a plugin may add extra data to be printed before or after a script when enqueueing a script. Quite a few plugins that we have enabled do this to define for example an ajax URL etc and it ...
0
votes
1answer
343 views

admin_enqueue_scripts not working

enqueue.php function sunset_load_admin_scripts( $hook ) { if($hook != 'toplevel_page_mypluginname') { return; } wp_enqueue_media(); wp_register_script('sunset-admin-script',...
0
votes
1answer
135 views

Wordpress and Advanced Custom Fields and Flickity

I am trying to add [Flickity Carousel][1] into my Wordpress theme. I was successful yesterday. However, when I returned to my theme this morning the carousel files are not loading. I am not sure what ...
0
votes
0answers
12 views

WordPress Menu Item Script Dropdown Login

I have a client I'm redoing a website for on WordPress and I'm trying to implement a login system that when they click on the menu item at the top of their website, it has a login that drops out and ...
0
votes
1answer
62 views

Unable to declare AOS library in functions

Greeting WP Devs, I am planning to transfer the script libraries in my function.php . In my function.php I registered AOS function mypage() { if ( is_page( 'mypage' ) ) { wp_register_script( '...
3
votes
2answers
424 views

Load CSS/Javascript in frontend conditionally if block is used

Assuming I have no infinite scroll or anything else going on in my theme: Is there a way to enqueue my custom Gutenberg block styles and scripts so they are only (lazy) loaded in the front-end when ...
0
votes
1answer
70 views

enqueue admin styling and scripts only on plugin page

I'm still learning so please bear with me if I sound a little confusing. Having lots of fun BTW while I learn. I'm creating a plugin with admin specific JS and CSS but I don't want those scripts and ...
0
votes
0answers
20 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
2answers
118 views

enqueue_script with filemtime javascript not working

Hey guys so I'm trying to enqueue a javascript with filemtime but every time I do it the custom js script I wrote doesn't seem to enqueue. function add_js_scripts(){ wp_register_script('lib', ...
1
vote
0answers
455 views

Preload key requests using wp_enqueue

I'm currently doing some speed optimisation and one of the main things scoring the site down is:- "Preload key requests 2.64 s Consider using to prioritize fetching resources that are currently ...
0
votes
0answers
23 views

Jquery enqueued script in child theme not proccing

I created a child theme of the theme twenty-seventeen. I want to add some scripts, especially Jquery libraries and some custom Jquery to animate the homepage. This is what I have in functions.php (...
0
votes
0answers
383 views

Uncaught ReferenceError: jQuery is not defined

It is a well discussed problem, but I can't find the issue (I've been researching it for days now); Uncaught ReferenceError: jQuery is not defined jQuery seems not te be loaded within my custom ...
0
votes
1answer
37 views

Why my wp_enqueue_script doesnt work on some page?

My wp_enqueue_script from my theme is working on home page and not on other page. This is my web : https://welgo.id. And here is not working : https://welgo.id/listing/rs-bandung-eye-center-bandung/ ...
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
0answers
21 views

Set a parent script presence status true so that child scripts load in wordpress

I didn't know how to write a good title for my problem. I'm trying to integrate some scripts in js file and dequeue them to decrease browser requests. So let's say we have some child scripts which ...
1
vote
3answers
60 views

Enqueuing javascript files

I'm trying to enqueue a JS file (located at /js/example-script.js), just to get an alert on page load. Can anyone tell me what I'm doing wrong? In my example-script.js: jQuery(document).ready(...