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
36
votes
5answers
125k views

ajaxurl not defined on front end

I am trying to create a ajaxform on the front side. I am using the code jQuery.ajax( { type: "post", dataType: "json", url: ajaxurl, data: ...
0
votes
1answer
13 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 ...
0
votes
1answer
896 views

Conditions for admin get_current_screen action parent_file edit.php?post_type=page

I have a plugin that requires scripts to load for an admin panel in the page-attributes template drop-down on page post type. However this script causes a Uncaught TypeError: on post post types ...
1
vote
1answer
671 views

how to en-queue jQuery to load before the </body> tag

I've enqueued all my scripts on function.php to load before the tag by passing 'true' to the fifth argument. It does works for all of them BUT jquery, any idea what I'm doing wrong? ...
0
votes
0answers
11 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', ...
0
votes
0answers
14 views

Is there a way to populate return in_array($GLOBALS['pagenow'],array( 'wp-login.php' ))?

The function below checks if the current page is the wp-login.php page. If yes, it avoids enqueuing styles or scripts. function is_login_page() { return in_array( $GLOBALS['pagenow'], ...
0
votes
2answers
2k views

Ajax is not defined

Stack Exchange long time listener, first time caller. I have found examples on the developer.wordpress site but I have been still struggling. Localizing scripts: wp_localize_script() In my theme's ...
0
votes
0answers
14 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 ...
1
vote
2answers
2k views

wp_dequeue_style and wp_dequeue_script not working on server but does work on local xampp

This is my entire code and it is working perfectly in my local system xampp but not working on server. function taqyeem_dequeue_scrips() { if(basename($_SERVER['REQUEST_URI'])=='my_page' || ...
0
votes
1answer
638 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
3answers
1k views

How to delay display of page elements until enqueued script has injected html

I am enqueuing some javascript that injects SVGs into my page's DOM (called SVGInjector); it works great except for one thing: there is an undesirable "blink"/shift of elements on my screen ...
2
votes
3answers
1k views

Relative path instead of absolute for wp_enqueue_script

When you enqueue scripts or styles with the following: function themeslug_enqueue_style() { wp_enqueue_style( 'core', '/style.css', false ); } add_action( 'wp_enqueue_scripts', '...
7
votes
1answer
17k views

How to use wp_localize_script in custom page template?

I have the template called homepage that is assigned to the home page and bottom of a template I have a script tag. now I want to use my JSON in that script tag. home-template.php <?php add_action('...
1
vote
1answer
696 views

enqueue styles for only mobile wp

I tried to enqueue some styles on mobile only using wp_is_mobile() function, but it always give me true, Here is the code (From functions.php file) : add_action('wp_enqueue_scripts','...
0
votes
1answer
28 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 ...
0
votes
1answer
947 views

Add a Script button in W3 Total Cache plugin not working due to conflicting jQuery version

While trying to fix the Render-Blocking issue on my website, I ran into a problem with the W3 Total Cache plugin on its Minify settings page. The two buttons to add JS (Add a script) and CSS (Add a ...
0
votes
1answer
20 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&...
0
votes
1answer
565 views

How to dequeue the default CSS styles on the wp-login.php page?

I'm loading my own stylesheet on the wp-login.php page using the login_enqueue_scripts hook so I have no need for the default styles that come with that page. Is it possible to dequeue styles ...
15
votes
3answers
44k views

How to properly dequeue scripts and styles in child theme?

I made a parent theme and a child theme in one of my project. I enqueued CSS and JavaScripts in my parent theme like below: function project_necessary_scripts() { //Stylesheets ...
0
votes
0answers
21 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, ...
0
votes
2answers
1k views

javascript and css not loading properly in WordPress site

I managed to make my code working via codepen as you can see if you visit the link here Now trying to implement on a WordPress test site it looks like my javascript is not working as well as the ...
0
votes
2answers
1k views

custom post with loading script per single post

I read many Q&As here on SO...(and elsewhere but they don't count...lol) I think I follow the rules of WP.org but still it does not load the scripts. Scenario: Custom template for post in Php: &...
3
votes
1answer
2k 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
1answer
2k views

Adding javascript script to header via functions.php

I've posted a very similar question to this in the past but I'm still having trouble and I have new updates. This is my website (http://cryptoportugal.com/) and I'm trying to insert a Javascript ...
0
votes
1answer
916 views

How do I display the handle for all front-end enqueued scripts in plugin options page?

I use the following function in my plugin to display all the scripts handles in my plugin options page but it display only the handles of admin scripts: function my_detected_scripts() { global $...
0
votes
1answer
1k views

How to add JS snippet before closing <head> tag?

I'm setting up jQuery UI on one of my WordPress pages that uses a custom template (course-landing-page.php). I enqueued the scripts for jQuery UI the proper way, but I need to add a JavaScript snippet ...
1
vote
1answer
2k views

How to insert html/css/javascript code to wordpress plugin

I'm trying to show a modal dialog when user get registered (action_hook: user_register) using the woocommerce plugin, but without having any result. I would appreciate any help! The code is shown ...
0
votes
1answer
46 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 ...
20
votes
5answers
30k views

How can I get a list of all enqueued scripts and styles?

I'm creating a plugin and I want to get the list of all scripts and CSS used by other plugins. This is my function: function crunchify_print_scripts_styles() { $result = []; $result['...
2
votes
1answer
950 views

Adding wp_enqueue_media(); causes problem

I want to add the media uploader in the theme options page. If I add following code in the options page, the media uploader works fine there, but it creates problem in the standard posts featured ...
1
vote
3answers
232 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'); ?> ...
2
votes
2answers
1k views

Adding custom fonts (local) to WordPress?

I have this code: @font-face { font-family: 'Miller Banner Light'; src: url('fonts/Miller-Banner-Light-01.eot'); /* IE9 Compat Modes */ src: url('fonts/Miller-Banner-Light-01.eot?#iefix') ...
0
votes
0answers
25 views

Fire action after enqueue script

I have a color switcher but its css files load before default css files.so, it doesn't work good.I want to fire it after enqueue script.after all css and js files on the website, I want to load my ...
43
votes
5answers
70k views

How to override JavaScript files in child theme?

I'm loading some JavaScript files in the parent theme. The path in the parent theme is: scripts > custom.js In the child theme, I'm creating the same path (scripts > custom.js) and changing ...
0
votes
1answer
21 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 ...
0
votes
3answers
781 views

Enqueue All Stylesheets Found In a Theme Folder

Is there a built-in Wordpress function that will allow you to enqueue all stylesheets for a particular theme? I have a directory structure that looks like: -my-custom-theme -css -header....
7
votes
5answers
18k views

tinymce is not defined when not using wp_editor

I am using jQuery tinyMCE to populate dynamically generated text areas with tiny MCE editors. When I use the WordPress wp_editor function before I call the jQuery version, I have no issues. If I do ...
0
votes
0answers
20 views

wordpress plugin add page when activate

I have written a WordPress plugin and want to make new page when plugin activate I tried by the following its loading only html its not including css style-sheet which is included in html file if ( ! ...
0
votes
1answer
2k views

Enqueueing Script to footer puts it at the very bottom

So I've got a bit of an issue, and not sure what the problem is. I'm trying to enqueue javascript in the footer of my Wordpress site. The footer looks like this: </footer> </div> <...
0
votes
0answers
34 views

Can't replace Gutenberg editor's pre-publish conditions with my own

I'm trying to adapt Welcher's answer here to replace Gutenberg's default pre-publish conditions with my own - namely for requiring that a category and a featured image are set. However, no matter what ...
0
votes
4answers
714 views

Problem with wp_enqueue_script

I've spent a lot of time trying to solve this problem and am really lost. Notice: wp_enqueue_script was called incorrectly. Scripts and styles should not be registered or enqueued until the ...
0
votes
2answers
802 views

How can I enqueue comment-reply script only on certain page?

I'm trying to enqueue comment-reply.js script only on a certain page but something is wrong with my code. Can someone hint things here? <?php if ( is_singular('1740') && (!is_home() || !...
1
vote
1answer
31 views

Enqueue script/style if certain widget has certain value

I want to build a widget by which various social media sharing buttons can be added to front end. In the widget form there will be many checkboxes for social media. Since these sharing buttons require ...
0
votes
3answers
1k views

Bootstrap slider not working

I have a html bootstrap slider which works fine with captions and everything.I would like to integrate it into my Wp theme (my forst one, so total newbie).I found a code, which seems to helo, but it ...
2
votes
2answers
592 views

How can I make sure my JS script gets executed first, among other scripts?

I have this script that cuts down my menu and adds a "+" dropdown if there are too many menu items in an attempt to prettify long menus, as such: Without the script running: Which I call in ...
0
votes
0answers
109 views

JQuery UI button not working in the Wordpress 5.8 theme

I have enqueued the necessary scripts via wp_register_script and wp_enqueue_script in Wordpress (v 5.8): <script type='text/javascript' src='https://<mywebsite.com>/wp-includes/js/jquery/...
1
vote
1answer
102 views

Is my approach to enqueue styles inefficient?

I'm kinda new to wordpress and programming in general. I have the following question. Recently I came across this article and wanted to use this approach in the wordpress theme I'm working on. I wrote ...
4
votes
3answers
7k views

Add `datetimepicker` to form

I have a form where i would like to add a datetimepicker(). I must be doing something wrong. I have done the following: In my header.php <?php wp_enqueue_script("jquery"); ?> In my functions....
1
vote
0answers
32 views

How to enqueue JavaScript file that depends on CSS stylesheet

I'm trying to set up a build process for JS/CSS assets to work with my WordPress theme. In my JavaScript file, I can do this: // src/button.js import React from 'react'; import './Button.css'; ...
0
votes
1answer
1k 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 ...

1
2 3 4 5
21