All Questions

Filter by
Sorted by
Tagged with
1
vote
1answer
53 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
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 ...
1
vote
3answers
47 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
2answers
134 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
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
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
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
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
2answers
343 views

Enqueuing script is adding extra text for google maps [closed]

I'm setting up a google map on my site and I'm trying to set the enqueue my scripts up but am getting an error: I have placed this code in my functions.php (actual api key not used here): function ...
0
votes
0answers
46 views

How do I keep children of certain parent menus expanded by default on a sidebar?

We are using advanced sidebar pages menu: https://wordpress.org/plugins/advanced-sidebar-menu/ to expand / collapse children menus on a sidebar. By default, the parent sidebar menu is expanded, ...
0
votes
1answer
67 views

How to use wp_register_script / wp_enqueue_script for multiple queries

I have a wp_register_script / wp_enqueue_script and need to reuse this for multiple states, how do I do this? This is the code: wp_register_script( 'scount', get_template_directory_uri() . '/...
2
votes
1answer
26 views

Can't get JS code to work with shortcode

I am trying to create a plugin and I've got stuck. I am trying to register and enqueue a script from a shortcode: This is my shortcode: add_shortcode( 'gear-guide', 'gg_product_front_end' ); This ...
1
vote
1answer
46 views

Why won't my scripts load?

I am having trouble loading scripts in functions.php I've done this before so I'm sure I'm overlooking something but as far as I can tell it is correct and I have tried copying and pasting from other ...
1
vote
1answer
310 views

Adding multiple wp_register_scripts for templates in WordPres?

How do I add multiple JavaScript files to templates? The below works great for only ONE Javascript file which loads on the templates called template-1.php and template-2.php - but I have another 3 ...
0
votes
1answer
425 views

Use js script from one plugin in another plugin

I have two plugins that work together (one is an add-on of sorts). In the "main" plugin, I have a js function in a file located like so: wp-plugins/main-plugin-name/js/main-js.js If my secondary ...
2
votes
3answers
361 views

wp_register_script multiple identifiers?

In order to avoid poor performance with multiple <script> tags I do concatenation of scripts regularly and produce one single bundle.min.js JS file and 'jsbundle' identifier. Problem is, things ...
0
votes
1answer
425 views

JavaScript file successfully registered but does not render correctly

I have this page that uses colorbox to popup information about the staff members when the photo is clicked. My page is a child theme of a West and I inserted the following code in the functions.php /...
0
votes
2answers
494 views

Add crossorigin to SCRIPT tag

Is there any way to add a crossorigin attribute to a custom registered JavaScript? wp_register_script('foo', 'http://cdn.domain.com/script.min.js', null, '1.2.3'); wp_enqueue_script( 'bar', '/path/to/...
0
votes
2answers
527 views

Adding JS in header when using wp_enqueue_script in a shortcode

I'm trying to enqueue a JavaScript file in the header of my website. If I add the following in my main plugin file the JS is included in the header: function wpdocs_theme_name_scripts() { ...
1
vote
1answer
715 views

Best spot for wp_register_script() and wp_register_style()

I need to enqueue multiple scripts and styles in my plugin. However, I do not like the idea of calling wp_register_script() and wp_register_style() every time I need to call wp_enqueue_script() and ...
2
votes
1answer
807 views

Can't move jQuery to footer

Below two methods did not help me. My jQuery is always on the head section. What can be the reason? Method 1: (adding below code to function.php) if (!is_admin()) add_action("wp_enqueue_scripts", "...
1
vote
1answer
1k views

WP .js script file not loading

I have looked all over the place and did not find a solution to my problem. I have a child theme where I have a functions.php file where I try to register and enqueue the script the following way: ...
0
votes
3answers
820 views

Scripts not loading through function Method in Wordpress Theme

I am trying to load CSS and Javscripts through the functions. CSS are loading, but dont know what mistake has been done that javascripts and Jquery are not loading through the functions method. I ...
5
votes
1answer
4k views

Cannot deregister a script using wp_deregister_script

I am trying to get rig of the Disqus script on my front page, but unfortunately I cannot manage how to do this. Here is a little story of the steps I've done. Find the script name in the source code ...
1
vote
1answer
121 views

Pass $this to function nested in another public function of the same class

I'm building a plugin using the WordPress Plugin Boilerplate by DevinVinson. I'm adding a public shortcode function for wich I will need some resources (js and css), I want to enqueue scripts (that ...
0
votes
2answers
343 views

When to use add_action when registering/enqueuing scripts

When should you use add_action to enqueue or register a script, vs just using wp_register_script and/or wp_enqueue_script? In other words, both example 1 and example 2 below seem to accomplish the ...
4
votes
2answers
2k views

Enqueue script only when shortcode is used, with WP Plugin Boilerplate

I'm building a plugin using the WordPress Plugin Boilerplate by DevinVinson. Everything works fine, except one thing: I'm trying to enqueue scripts and css only when a shortcode is present in the ...
2
votes
1answer
1k views

Adding jQuery dependency prevents my script from enqueuing/loading

This works: add_action('wp_enqueue_scripts', 'custom_script_enqueue'); function custom_script_enqueue() { wp_enqueue_style( 'customstyle', get_template_directory_uri() . '/css/theme....
0
votes
1answer
349 views

Remove snippets of JS from core

I can see these bits of code in the source in my wp install: <!-- jQuery --> <script type="text/html" id="tmpl-wp-playlist-current-item"> <# if ( data.image ) { #> <img ...
0
votes
1answer
70 views

True parameter but jquery register in header and not in the footer with wp_register_script

I want to register jquery.js in the footer, but even with the true parameter it registers in the header. Here is the code. The other scripts are registered in the footer. Only jquery does not. ...
0
votes
1answer
52 views

How to get, in WP page's script, a wp enqueued script (in Functions.php)?

I’m very new to WP, and to JS as well, and need to do a simple change to existing code, so forgive my ignorance… For getting the current User Id I followed examples and added an action + function to ...
0
votes
1answer
229 views

How to register script with null value for version?

Can someone explain the version argument in wp_register_script()? According to the codex it is added to the URL as a query string for cache busting purposes. It also says if the $ver argument is set ...
0
votes
1answer
3k views

wp_enqueue_scripts does not work

I am creating a theme for Wordpress, but the wp_enqueue_scripts does not work. The code that is in functions.php is: <?php function scripts_and_styles() { if ( ! is_admin() ) { ...
1
vote
1answer
154 views

How to cancel `wp_print_scripts`?

I want to load all the scripts in $wp_scripts with my own JS function after the window.onload event. Is there a simple way to prevent wp_print_scripts from printing the default list of <script> ...
0
votes
1answer
903 views

jQuery plugin not loading

I am trying to use the below function to enquue 2 scripts (one internal, one external). The internal one ('custom_script') is working, but the 2nd one ('formValidation') isn't (I get a 'validate() is ...
2
votes
1answer
3k views

wp_enqueue_script with dependencies doesn't work

I'm having this code: wp_register_script('parent','parent.js', array('child'), '1', true); wp_register_script('child', 'child.js', array('grandchild'), '1', true); wp_register_script('grandchild', '...
1
vote
3answers
1k views

Loading scripts with wp_register_script and wp_enqueue_script

How could I include the following script and stylesheet in a wordpress plugin if they only need to load in the admin panel? <script type="text/javascript" src="/wp-includes/js/jquery/jquery.js?ver=...
0
votes
3answers
2k views

Using wp_enqueue_script on scripts that contain PHP

I'm am working on a WooCommerce website, and have all my jQuery in the footer inside script tags. I use PHP to filter out the needed scripts for any particular page. However, I would like to use the ...
1
vote
3answers
2k views

WordPress script file version numbers changing in live environment

I'm registering my javascript files for Wordpress in my functions file as so: if( !function_exists( "theme_js" ) ) { function theme_js(){ wp_register_script('wpbs-scripts', ...
0
votes
1answer
85 views

Enqueue script: link not working in page source

I am using the Front-End Editor plugin of Scribu at my website. I want to enqueue it, because I want to use it alongside my caching plugin, but that one only works when JS files are enqueued. The ...
1
vote
3answers
1k views

Why isn't jQuery 2.1 loading in the header?

Because I want to use jQuery 2.1 instead of 1.11, I first have to de-register jQuery. Then register it with the new values. : add_action( 'wp_enqueue_scripts', 'add_scripts' ); function add_scripts()...
0
votes
0answers
574 views

How to wp_enqueue_script with html?

I want to wp_enqueue_script multiple javascript with html and css. I place the html code in a page, but it's not working on my side. Only plain text is displayed. Here's the link: http://goo.gl/...
1
vote
2answers
942 views

Most elegant way to enqueue scripts in function.php with foreach loop

I wonder is there a way of running wp_register_script and enqueue with the help of foreach loop to manage label and dir? For example, function wbs_app_components(){ $scripts_list=array( ...
1
vote
2answers
1k views

Use wp_enqueue_scripts from included php file

I've got a realy hair pulling problem here. I've started cleaning up a plugin i've made and sort some of the functions in diffrent files. but i've got a problem with wp_enqueue_scripts. when i ...
0
votes
1answer
3k views

Jquery function working in Dev Console but not otherwise [duplicate]

Can someone help me utilize native wordpress jquery to run my function? The only working test i have done is to load an external jquery resouce via the chrome dev console and then add my function to ...
0
votes
2answers
649 views

Localizing script to pass a value to a javascript function

i'm really getting crazy about this. after hours of trials, i can't get out of this. I'm trying to pass a php variable value to an enqueued jquery script but i can't. here is my code. php : ...
11
votes
1answer
23k 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 ...
-1
votes
1answer
3k views

Enqueue scripts in the footer

I'm trying to modify a plugin for enqueue scripts in the footer, because my jQuery link is in the footer. The plugin: add_action('wp_enqueue_scripts', 'fjgwpp_addCSSandJS'); function ...
53
votes
7answers
34k views

Enqueue Scripts / Styles when shortcode is present

What is the idea way to register/enqueue scripts and/or styles for use in plugins? I recently made a plugin simple plugin to add the user avatar/gravatar with a shortcode. I have different style ...
2
votes
1answer
2k views

Using multiple versions of jQuery while still calling it like WP likes

I have two JS plugins inside my plugin. One uses jQuery 1.7.1 and the other 1.9.1. I need to have each of them use different version. This is how things are at the moment: Plugin php file: ...