Skip to main content

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
19 views

How can I access custom data fetched from posts in a javascript script?

I am trying to fetch the lat, long data from custom fields in my posts in order to make a map layer with them (openlayers). I added custom long and lat fields to each post I created a function to ...
Oh-No's user avatar
  • 101
1 vote
1 answer
68 views

Wordpress Gutenberg Custom Block the viewScript does not get loaded on the frontend when my block is inserted

I recently developed a custom Gutenberg block by utilizing the @wordpress/create-block package, which effectively generated a full plugin framework. I simply needed to tweak some existing files to get ...
Daniel V.'s user avatar
  • 131
1 vote
0 answers
37 views

Custom gutenberg block refuses to load viewScript and I don't know why

I've been struggling with this for hours. I used the @wordpress/create-block package to generate a template for me to create my first block. I've managed to create a hero block with an image uploader ...
Daniel van der Velden's user avatar
1 vote
1 answer
96 views

Gutenberg Static blocks: viewScript doesn't import css for frontend?

I am building static block slider (Swiper JS). Used wordpress/create-block https://developer.wordpress.org/block-editor/reference-guides/packages/packages-create-block/. Besides importing the JS & ...
Ion T's user avatar
  • 25
0 votes
0 answers
27 views

Why is my JS not working on initial load?

I'm having weird issues with one of my JS Files that I added via a child theme. I have enqueued it in the functions.php and added some vars with wp_localize_script. wp_enqueue_script('header-astra', ...
Lina Staudt's user avatar
1 vote
1 answer
577 views

Asynchronous enqueue of the Google Maps API

I am loading the Google Maps API on a lot of Wordpress sites and I have always added it with an enqueue. Lately, we have been getting the following warning on the console: "Google Maps JavaScript ...
Sergi's user avatar
  • 11
0 votes
1 answer
55 views

wp_enqueue_script() with unknown path and maybe symlink

I'm developing a plugin that may also be used as a library in themes or plugins. I need to enqueue a custom script, but I cannot know the absolute path to the script, as the final location of the ...
Gerard Reches's user avatar
0 votes
0 answers
22 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
26 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
233 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
55 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' ) ); } /* ...
OHICT's user avatar
  • 133
0 votes
0 answers
19 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
  • 83
1 vote
1 answer
284 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
  • 155
0 votes
0 answers
51 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
15 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
294 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
87 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
178 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
  • 688
0 votes
1 answer
241 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 ...
OHICT's user avatar
  • 133
0 votes
1 answer
73 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
722 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
744 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
162 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
  • 447
4 votes
1 answer
296 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
144 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
366 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
609 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
152 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
402 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
61 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
401 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
515 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
236 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
31 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
36 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
185 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
  • 579
0 votes
0 answers
129 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
23 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
  • 449
0 votes
1 answer
3k 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
153 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
1k 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
100 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
1k 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
255 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
162 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
  • 215
1 vote
0 answers
399 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
539 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
81 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
46 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

1
2 3 4 5
22