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, ...

learn more… | top users | synonyms

27
votes
1answer
6k views

Where is the right place to register/enqueue scripts & styles

I am using WordPress 3.1.4 by now. I am confused with where (which hook) do I use: to register and/or enqueue scripts and styles on front- and back-ends? Questions: Which are right hooks to ...
9
votes
1answer
7k views

How to add defer=“defer” tag in plugin javascripts?

I couldn't add defer tag in plugin javascripts. Google developer pagespeed test suggests me to add defer tag in contact form 7 javascripts. This is how contact form 7 includes javascript in header. ...
3
votes
3answers
3k views

Adding jquery and thickbox to WordPress theme

I would like to add thickbox for the template which I develop to WordPress. At this time I'm trying with a clean template that have only header.php, footer.php,index.php, and functions.php. I've ...
23
votes
7answers
9k views

Conditionally Loading JavaScript/CSS for Shortcodes

I released a plugin that creates a shortcode and requires a JavaScript file and a CSS file to load on any page that contains that shortcode. I could just make the script/style load on all pages, but ...
2
votes
2answers
2k views

How do I implement the Wordpress Iris picker into my plugin on the front-end?

This question here is asking the same question as I am, but there were no adequate answers nor a selected correct answer so I am asking again hoping if I ask in a more coherent manner I might get a ...
6
votes
5answers
1k views

Adding Additional Attributes in Script Tag for 3rd party JS

I ran into this when attempting to integrate Dropbox's drop in chooser API to a plugin I'm writing. The API documentation instructs you to place the following script tag at the top of your file: ...
1
vote
1answer
295 views

wp_enqueue_script isn't connecting my custom js file

I am using wp_enqeue_script to link to a custom.js file in my plugins folder. However I am expecting a link to show up on the page but it doesn't is there something else I am supposed to other than ...
5
votes
1answer
2k views

Load js/css files only on specific admin UI pages

How do I adapt this solution to work with my plugin? (Please see the link). I enqueue my css and js script as follows: function my_plugin_init() { wp_enqueue_script('my_plugin_script', ...
7
votes
2answers
6k views

Load a script just to custom post type in admin

I have created a custom post type "portfolio" with something like this : $args = array( 'labels' => $labels, 'public' => true, 'publicly_queryable' => true, 'show_ui' => ...
3
votes
2answers
6k views

Notice that the wp_enqueue_style is not being called correctly!

I get this error due to one of the plugins which I rely on. Notice: wp_enqueue_style was called incorrectly. Scripts and styles should not be registered or enqueued until the wp_enqueue_scripts, ...
18
votes
5answers
9k views

How do I enqueue styles/scripts on certain /wp-admin pages?

I have two simple functions that load stuff using wp_enqueue_style() and wp_enqueue_script(), something like these: function admin_custom_css() { wp_enqueue_style( 'stylesheet_name', ...
9
votes
5answers
6k views

Including jQuery and JavaScript files the correct way

I'm having some trouble with this. I'm not sure how to do it the correct way, and I read so many different techniques and ways to do it that I don't know what to make of it. Some questions and ...
15
votes
4answers
2k views

Could the WP script/style loader be used to concatenate and gzip scripts and styles in the front-end?

WP has a nice javascript loader included in wp-admin: http://core.trac.wordpress.org/browser/tags/3.0.4/wp-admin/load-scripts.php and a CSS loader: ...
3
votes
2answers
373 views

What are the benefits of using wp_enqueue_script?

Is there any real benefit to using wp_enqueue_script on small self-managed sites? For instance, Modernizr, why enqueue it through a function rather than call it directly inside the document head? I ...
10
votes
5answers
7k views

wp enqueue inline script due to dependancies

Is there a way to use wp_enqueue_script() for inline scripts? I'm doing this because my inline script depends on another script and i would like the flexibility of inserting it after it's loaded. ...
4
votes
1answer
2k views

How do I get the $handle for all enqueued scripts?

Is there some way to get the $handle for each script that has been enqueued? Is there some array that holds all the handles so that I can loop through it and do something using each $handle?
3
votes
2answers
2k views

How can I de-register ALL styles all at once? And same with Javascript?

How can I get all enqueued styles or scripts and then deregister them all at once?
11
votes
1answer
6k views

How do I dequeue a parent theme's CSS file?

My parent theme (Starkers) adds a CSS file that I'm trying to remove (I want to use @import instead so I can override styles more easily). Starkers has the following in its functions.php: add_action( ...
6
votes
1answer
4k views

Register and enqueue conditional (browser-specific) javascript files?

The WP.SE community has always advised the use of wp_register_script and wp_enqueue_script for adding scripts in a theme/template (and likewise, wp_register_style and wp_enqueue_style for ...
3
votes
3answers
11k views

How to add a javascript snippet to the footer that requires jQuery

I know I can add a script file to the footer of wordpress that requires jquery using this code: <?php function my_scripts_method() { // register your script location, dependencies and version ...
2
votes
4answers
3k views

Asynchronous Javascript Loaders

I'd like to take advantage of loading my scripts while the page is loading. ie. Yepnope, head.js etc... But I also want to be able to enqueue the script so other plugins don't try adding their own. ...
6
votes
2answers
5k views

How to dequeue a script?

Wordpress has wp_enqueue_script() but not a wp_dequeue_script() function, so what would be the best way to dequeue a script? I'm using LAB.js to load all of my scripts rather than enqueueing them ...
4
votes
1answer
280 views

Concatenate and minify dependencies for enqueued JavaScript files

I'm loading a JavaScript file using wp_enqueue_script into my theme. However, along with it, I'm loading several jQuery files as well, as dependencies for the enqueued script (which has already been ...
1
vote
1answer
1k views

Adding Colorpicker Field To Category

I want to add a custom field to my categories where the user can color code them. I've added the field but I want to use built in colorpicker (either tinyMCE or the farbtastic) to give the user an ...
5
votes
7answers
5k views

wp_enqueue_script adding conditional statement not working

This is the code im using in my functions file: add_action('init', 'sort_out_jquery_pngfix_frontend'); function sort_out_jquery_pngfix_frontend() { global $wp_scripts; if(!is_admin()) { ...
3
votes
1answer
124 views

Hyphens vs. periods in the script slug in wp_register_script?

I have seen script and style handles written in two different ways in wp_register_script and wp_enqueue_script (the same applies to wp_register_style and wp_enqueue_style): wp_register_script( ...
18
votes
2answers
5k views

Check if a script/style was enqueued/registered

Is it possible to test whether a script or a style was registered using wp_register_script/_style or wp_enqueue_script/_style? All functions doesn't return a value and I'm completely clueless. I ...
2
votes
2answers
1k views

Wordpress Enqueue Script Chaos (jQuery & Foundation.js)

I've been working on building a theme for the past couple days now, and I've run into a wall. While I originally included foundation.js as an enqueued script, I couldn't remember why I had added it. ...
7
votes
1answer
3k views

wp_enqueue_scripts, wp_register_scripts, wp_print_scripts: i'm confused

I've been reading up a bit on this subject, but the more I read - the more confused I get. Can someone explain to me in short what's the exact difference between wp_enqueue_scripts, ...
7
votes
1answer
4k views

When should I use wp_register_script() with wp_enqueue_script() vs just wp_enqueue_script()?

I'm having trouble understanding when you need to use wp_register_script(). Currently, I just use something like: add_action( 'admin_enqueue_scripts', array( $this, 'enqueue' ) ); function enqueue() ...
3
votes
3answers
1k views

How to enqueue script if widget is displayed on page?

I created a widget that uses a jquery plugin, and I used is_active_widget to enqueue the script, it's working fine but it's also including the script even on pages that doesn't show this widget. so is ...
3
votes
3answers
1k views

How can I remove the site URL from enqueued scripts and styles?

I'm dealing with an SSL issue and I would like to strip the domain from all scripts and styles being output via wp_enqueue_scripts. This would result in all scripts and styles being displayed with a ...
2
votes
1answer
512 views

WP_enqueue_script inside shortcode?

I've got shortcode that needs to include JS library only once and only there where it's used. function shortcode_function($atts, $content = null) { $class = shortcode_atts( array('something' ...
2
votes
2answers
5k views

wp enqueue style on specific page templates

I am in the process of a theme, I would like to add landing pages using page-templates. I cannot find anywhere that shows how to enqueue style or js for specific page templates. Any suggestions. Ex. ...
0
votes
2answers
579 views

wp enqueue script using scripts from cdn with a safety callback

I want to include several scripts and styles from a remote CDN... in this case bootstrap and similer files but i want to provide a safety net in the form of a callback in the case the CDN is down for ...
0
votes
2answers
2k views

Hook 'wp_enqueue_scripts' priority has no effect

In a theme I am working there are up to 3 Stylesheets. I am using the hook 'wp_enqueue_scripts'. The order of the stylesheets is important for overwriting styles. I have a code like this: ...
0
votes
1answer
326 views

Register script/style: Is it possible to customize the version query string via plugin?

Expanding on the question in the title: I would like to find a way (via a plugin) to use timestamps for the JS and CSS file version query strings that are output with wp_register_style and ...
0
votes
1answer
2k views

Remove a script from a template file using wp_dequeue_script

I thought I had read it was possible to use wp_enqueue_script() and wp_dequeue_script() directly in individual template files. However, when I add wp_dequeue_script( 'myscript' ); to the top of ...
4
votes
1answer
2k views

Make jQuery library load before plugin files

I am using a few jQuery plugins such as validate.js, but they all load BEFORE the Jquery library which is loaded automatically by WordPress and my theme. I need the plugins to load after - so is ...
4
votes
4answers
631 views

Why are admin scripts not printed

I am trying to enqueue/print scripts in the admin area. But they dont seem to appear. add_action('admin_init', function() { add_meta_box('portfolio-meta', 'Details', 'portfolio_metabox_details', ...
3
votes
1answer
124 views

jquery script not enqueued in child theme

I need a little bit of insight here with the following problem? I've created a child theme called 'test_child' which I am trying to extend in the following way: This is the test_child/functions.php ...
2
votes
1answer
1k views

How to get a jQuery script to run on a page?

I am having a hard time figuring out how to get a jQuery script to run on a Wordpress page of mine the "correct" way. I have followed this article and implemented what the first answer says to do. ...
2
votes
1answer
643 views

How do I enqueue(or delay loading of) <script> tags in individual page posts?

My customer has many pages with <script> elements including javascript. <script src="myscriptforthispageonly.js"></script> I'm trying to get all scripts to load in the footer ...
2
votes
1answer
309 views

Add script to footer - on post editor

How do you add a script on the footer of the post editor ? I'm adding a meta box under the post editor and I need to include a javascript before the closing body tag (on the footer) How do I achieve ...
2
votes
1answer
1k views

Problem using is_single() to enqueue script from functions.php

I'm having trouble only adding scripts to single post pages. I need to both include and exclude certain scripts using is_single() but it doesn't work either way I try it. I have the template tag on ...
2
votes
2answers
860 views

Is it possible to enqueue a script from a widget method (of extended WP_Widget object)?

I am creating a widget plugin that a user could potentially use multiple iterations of the widget multiple times on a single widget-area / multiple widget-areas on a single page. Because of its ...
2
votes
2answers
2k views

How to control what jQuery version to include, with wp_enqueue_script

I'm using a script that is based on jQuery, so I'm not enqueue-ing jQuery directly, but via passing it in the array of dependent scripts: ...
2
votes
1answer
183 views

Adding Scripts in the Admin Area

I'd like to enqueue scripts only for an admin page that I've created. There's an example of this here: ...
2
votes
3answers
1k views

Enqueue script only for IE

I want to use dd belatedpng so the PNG's on my website appear properly on IE. The script I've always used on non-wordpress websites was <!--[if lt IE 7 ]> <script ...
1
vote
3answers
157 views

Can I add styles to footer with $wp_styles->add_data?

I'm working on a script to easily move js and css scripts to the footer using the add_data function in $wp_scripts and $wp_styles. I know for scripts that if the group is greater than 0 the script ...