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
0 votes
0 answers
17 views

How to enqueue additional scripts and styles after loading another post into the DOM?

If have a post_showcase shortcode that takes in post_ids as parameters. The shortcode generates buttons that when click will load the given post into a modal. However, the shortcodes within the ...
Gus Beringer's user avatar
0 votes
1 answer
14 views

Selective styles and scripts inclusion

I'd like to know if is there any method that allows to include scripts on specific pages/templates depending if those page have a specific get_template_part inside. Example: I have more than one page ...
MKay's user avatar
  • 179
0 votes
1 answer
40 views

correct way to enqueue js and css files for wordpress shortcode?

I have created a php class file. I am enqueuing the required CSS and JS files in the class's constructor. public function __construct() { add_action('wp_enqueue_scripts', array($this, '...
SDeveloperj's user avatar
0 votes
0 answers
22 views

admin_enqueue_scripts not load custom scripts from cdn

I have this code in a plugin class DashboardCustomizer { public function __construct() { add_action( 'admin_enquque_scripts', array( $this, 'load_custom_scripts' ) ); } /* ...
ICTDEV's user avatar
  • 113
0 votes
0 answers
18 views

difference between code for admin, user facing (css, js)

So I have two pages, user-edit.php in the admin and a page for members to edit their own profiles. There is a group of section on both that has the same coding, the same css id's, the same classes, ...
Jocelyn Hunter's user avatar
0 votes
1 answer
22 views

the second js file enqueued inside wp plugin isn't read

Inside a wordpress plugin : The second enqueued js file isn't read, need I specify something ? Does registering is necessary when several js files are called (enqueued) ? function ...
imagIne's user avatar
  • 41
1 vote
1 answer
147 views

in_footer: gives syntax error

We used to have the following script in functions.php that worked for many years: add_action('wp_enqueue_scripts', function () { wp_enqueue_script('swiper-script', 'https://unpkg.com/swiper@8/swiper-...
th00ht's user avatar
  • 135
0 votes
0 answers
36 views

Javascript isn't loading when I use wp_enqueue_script, but CSS is when I use wp_enqueue_style

functions.php: function filmstarrrr_files() { wp_enqueue_script('filmstarrrr-main-script', get_theme_file_uri('/build/script.js'), NULL, '1.0', false); wp_enqueue_style('...
1mayersz's user avatar
0 votes
1 answer
13 views

My scripts won't load in, is this code correct?

Here is my functions.php <?php function my_custom_theme_styles() { // Enqueue your custom stylesheet named "style.css" wp_enqueue_style('style', get_stylesheet_uri()); } ...
bpub's user avatar
  • 1
0 votes
1 answer
127 views

contact form 7 form not working in admin panel

I am using cf7 form in wordpress admin panel: On front end its working fine but I need in admin panel. I have tried below code in functions.php but it did not work: add_filter( 'wpcf7_load_js', '...
Ravinder singh's user avatar
0 votes
2 answers
47 views

Correct way to enqueue js and css for external php scripts

I am developing a plugin that uses some external PHP library. That PHP library uses js and CSS. I want to enqueue that external library js and CSS using the Wordpress enqueue functions in Wordpress ...
SDeveloperj's user avatar
2 votes
1 answer
120 views

wp_script_add_data not working

We are trying to add "async" to our script using this code. However this is not added by wordpress. Not sure why it's not doing anything. function wp_mk_scripts() { if ( is_page(26202) )...
JoaMika's user avatar
  • 668
0 votes
1 answer
162 views

functions.php doesn't load all custom theme assets

I'm writing a simple wordpress theme. I've added this function inside the functions.php file and I've noticed that only style.css is loaded. Is there something wrong that will cause that the other ...
ICTDEV's user avatar
  • 113
0 votes
1 answer
39 views

Making the Google Maps API non readable

Our former developers created this code below. However, when it renders on our site, it displays the API key. Is there a better way to hide the API key while still enlisting the script to be executed? ...
HomeWell Web's user avatar
1 vote
1 answer
372 views

What is the standard way to use the version of React that ships with Gutenberg on the front end?

I want to create a Gutenberg block that uses React on the client rendered page (not the admin pages). Is React code split from the rest of Gutenberg? If so, how can I enqueue that specific bundled ...
lookyhooky's user avatar
3 votes
1 answer
441 views

Loading newest dependency javascript module file in functions.php

Continuing from this question: I have scripts enqueued in functions.php file so scripts load only on certain pages (I cut most of them in code below): add_action( 'template_redirect', 'plugin_is_page' ...
FilipD's user avatar
  • 73
1 vote
0 answers
95 views

admin_enqueue_scripts using hook_suffix vs GET page

My menu code: add_action('admin_menu', 'waf_admin_menu'); function waf_admin_menu(){ add_menu_page('WordPress Audio Filter', 'WordPress Audio Filter', WAF_CAPABILITY, 'waf_settings', '...
Toniq's user avatar
  • 437
4 votes
1 answer
206 views

Auto updating JavaScript dependancy in functions.php

I'm enqueuing scripts with dependency in functions.php file like: wp_enqueue_script('ads', get_template_directory_uri() . '/js/ads.js', array( ), '1.6', true); wp_enqueue_script('banners', ...
FilipD's user avatar
  • 73
0 votes
0 answers
100 views

How to add Gutenberg editor on frontend page?

I have a textarea on a public-facing page. I want to add Gutenberg editor to that textarea. I searched the official documentation but couldn't find anything. Any information will be helpful.
Salekin's user avatar
1 vote
2 answers
171 views

How can I specifically enqueue scripts for edit orders pages only

The problem is that enqueing script this way, I end up inadvertently targeting product pages and other pages also which use the post and post-new hook, as WordPress has many types of posts, not only ...
ptrcao's user avatar
  • 115
0 votes
3 answers
220 views

wp_enqueue_script doesn't load JS in plugin

I wrote the following code in a standalone plugin, but it doesn't work Please guide me how to modify the code, so the JS file is loaded. <?php /* Plugin Name: Copy post */ class CopyPostApi{ ...
Fardad Farhang's user avatar
-1 votes
1 answer
115 views

How to give path to files in plugins folder?

How to give path to enqueue in functions.php wp-content/plugins/dl-grid-addons/includes/wp-bakery/tsw/tsw-tools/assets/js/tsw-tools.js
015ra's user avatar
  • 9
1 vote
1 answer
211 views

How to securely set dynamic HTML content with JavaScript?

Description I have implemented a frontend script that gets a few text options from the server via wp_add_inline_script. When the user does an action the content should dynamically change to one of the ...
Josef Wittmann's user avatar
0 votes
1 answer
40 views

plugin not loading my css and js

Hi I'm using the standard way to load styles and scripts within my plugin. But I have no clue why it's not working. It's not shown in the network tab nor in the <head>. Can this cause issues ...
Jan's user avatar
  • 33
0 votes
0 answers
270 views

Warning: filemtime(): stat failed for wp_

Currently getting this warning in php. Warning: filemtime(): stat failed for https://madeupurl.com/wp-content/themes/madeup/assets/js/scripts.js in /var/www/wp-content/themes/madeup/functions.php on ...
HomeWell Web's user avatar
0 votes
1 answer
290 views

How to enqueue js script after another specific js script?

Hi I have a js script that needs to be included after a specific js script. function wpb_adding_scripts() { wp_register_script('egovt-add-js',get_stylesheet_directory_uri(). '/add.js','','1.1', true); ...
Andreea Onica's user avatar
0 votes
1 answer
174 views

Why do WordPress adds the id="handle-{js|css}" attribute to scripts and stylesheet?

When you enqueue a script the id="" attribute and the script handle (appended with the -js or -css termination) are automatically added to the generated <script> or <style> tag. ...
amarinediary's user avatar
0 votes
0 answers
19 views

Dequeue/deregister scripts for everybody but the administrator

I'm trying to dequeue/deregister some scripts (the code is working) but I want them to be dequeued/deregistered for every visitors excepted the admin. //Dequeue Styles function ...
Edouard30's user avatar
0 votes
0 answers
19 views

Bootstrap bundle present in page source but not working

I'm facing a very peculiar issue where the bootstrap css is working fine but the js is not working. The js shows in the page source. I am using cdn but I have also tried by downloading the bundle and ...
Patrick2997's user avatar
2 votes
1 answer
127 views

wp_script_is('enqueued') true, but file not requested in HTML

This is really confounding. In a child theme functions.php file, I have confirmed that WP thinks my script(s) are enqueued: add_action("wp_enqueue_scripts", "my_scripts_styles"); ...
MikeiLL's user avatar
  • 559
0 votes
0 answers
110 views

wp_enqueue_script JS code runs too late (after user begins interacting)

The issue is that we need to replace some HTML based on the user's user agent string but by the time the JS code is loaded and runs, the user is already interacting with the page. Is there some way to ...
Slbox's user avatar
  • 109
0 votes
1 answer
21 views

Enqueue Script in WordPress

How to enqueue script in WordPress ? When I am using below code script enqueue properly. wp_enqueue_script( 'adc-handlebars', get_template_directory_uri() . '/vendors/handlebars/handlebars.min.js', ...
Foysal's user avatar
  • 417
0 votes
1 answer
2k views

Adding google fonts to WordPress theme

I am trying to add google fonts to a custom WordPress theme. Therefore I tried to enqueue selected three font faces at once to make it fast loading. So, I use the below codes to register and enqueue ...
user2584538's user avatar
0 votes
0 answers
116 views

JS / jQuery in Elementor pages vs JS file

I have a lot of JavaScript and jQuery functions that are all working fine, but it's quite fragmented and hard to maintain as some are in Elementor HTML widgets, others in specific Pho functions annd ...
user2894986's user avatar
0 votes
1 answer
791 views

How to enqueue a script which is type module without using script_loader_tag filter?

I'm creating a theme and i want to upload it to envato. I have a javascript file that is type module and i can enqueue it and then use script_loader_tag filter to add type module to it by these lines. ...
Hosein's user avatar
  • 1
1 vote
0 answers
60 views

Change script type and src of plugins in theme

So I have to implement OneTrust which requires all <script type="text/javascript"> to be converted to <script type="text/plain"> and there are various plugins that use ...
Test2's user avatar
  • 21
1 vote
1 answer
746 views

Bootstrap and jQuery error: $ is not defined

I'm trying to use the Bootstrap collapse component and just can't get it to work. I believe the HTML is proper, but whenever I click on the element that should trigger the collapse, I get an Uncaught ...
Tatex's user avatar
  • 33
0 votes
1 answer
158 views

Ajax on the Administration Side of plugin - wp_localize_script - how to pass value from JQuery to PHP function in class?

I have built a plugin and I need to use ajax in the admin and have followed the documentation here: https://codex.wordpress.org/AJAX_in_Plugins However, this is out of date and I cannot find any ...
LeeTee's user avatar
  • 31
1 vote
0 answers
149 views

Is there a way to check for an attribute of a script when using script_loader_tag?

The block of code adds the attribute async to a array of Javascript files. Is there a way to check if the files have already have the attribute assigned and if yes, to skip it? function async_scripts( ...
Motivated's user avatar
  • 205
1 vote
0 answers
290 views

Wordpress load same script two times

I write a basic plugin with custom css/js. I use wp_enqueue_script for my custom script and use hook 'init' to register script in front-end page. But wordpress load this javascript file two times with ...
tecnico57's user avatar
1 vote
1 answer
447 views

Enqueue scripts not working with if is page conditional tag in functions.php

Is this even the correct way of including scripts on a specific page? function insert_mapsvg_scripts() { wp_enqueue_style( 'mapsvg_css', site_url('/mapsvg/css/mapsvg.css') ); wp_enqueue_style( '...
Biels's user avatar
  • 113
0 votes
1 answer
52 views

How to load Javascript code or functions.php later in a child theme?

I'm placing some JS code in functions.php in my child theme but it loads first than anything else. Thus, I'm trying to get it to load later than the rest cos it needs Jquery. I tried enqueuing WP's ...
ratib90486's user avatar
0 votes
1 answer
40 views

Run JS function when JQ enqueued

I would like to run a javascript function when jQuery is ready. This doesn't work: wp_enqueue_script('jquery'); ?> <script> (function() { doJQstuff() })(); </script> ...
Fluxian's user avatar
  • 130
0 votes
0 answers
196 views

Filter enqueued styles and scripts

I am looking for a way to reorganize the scripts/styles queue in WP. I am well aware of the fact altering the queue may have undesired effects, but in this case there are solid reasons for doing it ...
Álvaro Franz's user avatar
0 votes
1 answer
182 views

"Intercept" enqueing of 3rd party's JS file

I'm using a 3rd-party plugin, but I need to load the non-minified version of a specific JS file of the plugin, to avoid some image preloading caching; in the AJAX call when preloading some images, the ...
Faye D.'s user avatar
  • 127
-1 votes
2 answers
817 views

Can't seem to get javascript code working from child theme

my javascript code isn't working. I put the js folder next to the other folders, the astra-child folder, astra folder and other themes. Is this correct. Then in the js folder, I created custom_script....
Spencer Halstead's user avatar
0 votes
1 answer
284 views

Correct way to enqueue page specific CSS file

I am looking for an alternate way than using functions.php and applying conditionals based on each page's ID, instead I would like to enqueue the CSS right at the top of each page like this: <?php ...
Raging Vids's user avatar
0 votes
1 answer
25 views

Why won't wp_enqueue_script work within any plugin file?

I have a plugin, from which within one of the files I am trying to include a JS file the proper way: function inveroak_feed_search_enqueue() { wp_enqueue_script('inveroak-feed-search', ...
Lee's user avatar
  • 327
1 vote
0 answers
259 views

How can I manually enqueue plugin scripts

I am trying to manually use the accordion tool from wpbakery. Now before my question gets closed, my question is not about wpbakery. My question is how to load the correct scripts so that the ...
rudtek's user avatar
  • 5,979
0 votes
1 answer
77 views

jQuery will not work on page from snippet or file

I've been banging my head against the wall on this, My jQuery code runs perfect in CodePen, the WP site in console also runs it perfect, however I simply can not get it to run on the actual ...
RawalD's user avatar
  • 121

1
2 3 4 5
21