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
1 answer
13 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
51 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
  • 650
0 votes
1 answer
73 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
  • 105
0 votes
1 answer
24 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
116 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
159 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
58 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
  • 399
4 votes
1 answer
119 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
60 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
1 answer
63 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
2 answers
71 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
66 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
60 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
33 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
  • 31
0 votes
0 answers
160 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
94 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
0 answers
80 views

Should I use wp_register_style(), wp_enqueue_style, or both?

I am using a child theme and am trying to figure out how to include a Google font. I've looked at a few sites and forums, and from what I understand, the code should be added to the functions.php file....
Kristen's user avatar
0 votes
0 answers
11 views

How to load JavaScript modules with script_loader_tag hook?

defined('TEST_JS_DIR') or define('TEST_JS_DIR',plugin_dir_url(__FILE__).'js'); if(!class_exists('plugin_test')) { final class plugin_test { public function __construct() { ...
brittle_spirit's user avatar
0 votes
1 answer
93 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
15 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
35 views

How to enqueue structured data as file - jsonld file seems not to work

I would like to add my schema / rich snippet / structured data via functions.php: wp_enqueue_script( 'my-schema', get_template_directory_uri() . '/assets/schema/organization.jsonld' ); The ...
jasie's user avatar
  • 123
0 votes
0 answers
269 views

Uncaught ReferenceError: tippy is not defined

Just need some sanity check where I am going wrong. I am trying to load the tippy.js into my code and it's returning the standard not defined error. Queue script wp_register_script('tippy-js', &...
xaykogeki's user avatar
0 votes
0 answers
15 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
57 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
74 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
0 answers
30 views

Edit all $wp_scripts at once to $in_footer = false

How can I make all styles and scripts enqueued from theme and plugins be registered in <head>, I have over 30 styles and scripts, so would be nice to make a function that does this. So what I ...
zal ador's user avatar
  • 101
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
  • 407
0 votes
1 answer
670 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
92 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
485 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
38 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
0 votes
1 answer
485 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
  • 23
0 votes
1 answer
109 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
127 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
  • 181
1 vote
0 answers
163 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
304 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
48 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
27 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
147 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
126 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
531 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
203 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
19 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
  • 317
1 vote
0 answers
208 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,760
0 votes
1 answer
47 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
0 votes
1 answer
491 views

Add type to enqueued script inside plugin

So I don't know if this is possible, but I have a question - We are integrating OneTrust and one of the requirements was to change <script type='text/javascript'> to <script type='text/plain&...
theMap's user avatar
  • 25
0 votes
0 answers
51 views

Advanced method to control cache of enqueued style/script

I have a WordPress website with medium-level traffic, ~10,000 unique visitors a day. Arround 30% of my daily visitors are recurrent. I constantly make some UI improvements: colors, font-size, ...
Alexandro Giles's user avatar
0 votes
1 answer
628 views

Dequeue / Deregister script and replace it with a new plugin

I think I've read a dozen posts about dequeuing and deregistering scripts, but I haven't been able to make it work properly in my situation. My situation: The "uListing" plugins are part of ...
supernaut's user avatar
  • 101
2 votes
3 answers
1k views

Enqueue script o style only if a template part is loaded

I have registered some styles and scripts that should be loaded if a template part is loaded in a template file. For ex: in home.php <?php get_template_part( 'template-parts/external_links'); ?> ...
Alexandro Giles's user avatar
0 votes
1 answer
56 views

Do I just put the html in a page when enqueueng or do I also have to reference js file from the html page [closed]

I am trying to get my javascript to work in my page, but I have always just put the html on the actual page, but now am wondering if I am supposed to put the <script src before the html as well to ...
Spencer Halstead's user avatar

1
2 3 4 5
21