MU Advanced: Issues and Discussion
Welcome Guest
  • Good evening, Guest.
    Please log in, or register.
  • July 31, 2010, 05:45:58 PM
Home Forums Contact Tags FAQ Links News Login Register
* *
Navigation Menu
Search

Random Quotes
Whenever you set out to do something, something else must be done first.
- Murphy's Law
Pages: [1]   Go Down
  Print  
Author Topic: wp_default_scripts()  (Read 1021 times)
0 Members and 1 Guest are viewing this topic.
ZappoMan
Full Member
***

Karma: 1
Offline Offline

Posts: 157



View Profile
« on: October 06, 2008, 03:50:38 PM »

Can someone explain to me how wordpress decides which JS files to include? I can not figure out this code in wp_default_scripts()

In particular... you add all these scripts, many of which aren't needed on many pages, and somehow they don't get included when they aren't needed...  how does the core decide what is needed and what is not needed?

Why do I want to know? Well on my development environment for some reason the post.js script is being included on the link.php page... which really messes up that page. But somehow in production it works correctly...

REALLY BLOWING MY BRAINS!
Logged

Yep, that's me... riding my bike 204 miles in one day.
ron_r
Key Master
*****

Karma: 4
Offline Offline

Posts: 1143



View Profile WWW
« Reply #1 on: October 06, 2008, 08:10:55 PM »

When the scripts are "enqueued", there is a parameter indicating what page they apply to.
Logged

The key to problem solving is identifying the problem.
Luke
Key Master
*****

Karma: 5
Offline Offline

Posts: 3710



View Profile WWW
« Reply #2 on: October 07, 2008, 12:19:09 PM »

Examples:
Code:
<?php
wp_enqueue_script
'jquery' ); // include jquery;
wp_enqueue_script'luke-dashboard''/wp-admin/js/luke-dashboard.js'); // include custom js;
?>

Logged

10 frames?
Heh, that's for Quakers.

Note: This message may be Canadian friendly.

"Pornographic monster on the floor"
ZappoMan
Full Member
***

Karma: 1
Offline Offline

Posts: 157



View Profile
« Reply #3 on: October 28, 2008, 12:18:07 PM »

So here's the thing I still haven't been able to figure out...

When can you call this and be certain that it will add your script?
It looks like there's also a version for stylesheets.... what are the rules for that?

So the classic example is a plugin, that say, adds a widget. I'd rather that the JS and CSS not show up unless the widget is actually being instantiated... but the rules of engagement seem kinda sticky here.

I might not know I'm being instantiated until well after the header has been rendered... so what's a good coder to do?
Logged

Yep, that's me... riding my bike 204 miles in one day.
ron_r
Key Master
*****

Karma: 4
Offline Offline

Posts: 1143



View Profile WWW
« Reply #4 on: October 28, 2008, 09:09:05 PM »

The default filters code adds the wp_print_scripts function to wp_head.

If necessary, I embed the script/css in the widget in the plugin. Ex. recently to restyle some extra sign-up fields I included the style before the fields.
Logged

The key to problem solving is identifying the problem.
Luke
Key Master
*****

Karma: 5
Offline Offline

Posts: 3710



View Profile WWW
« Reply #5 on: October 29, 2008, 07:18:07 AM »

Quote
I included the style before the fields

Validate much? Tongue

Honestly, I wouldn't worry about it. Hooking into the head for an additional style, stylesheet, script, or js file is just fine.

You can hook into admin_head for the admin area as well.

Logged

10 frames?
Heh, that's for Quakers.

Note: This message may be Canadian friendly.

"Pornographic monster on the floor"
ron_r
Key Master
*****

Karma: 4
Offline Offline

Posts: 1143



View Profile WWW
« Reply #6 on: November 06, 2008, 09:25:54 AM »

Didn't have much choice because the styles I was overriding were also in the body of the signup form.
Logged

The key to problem solving is identifying the problem.
Tags: scripts 

Pages: [1]   Go Up
  Print  
 
Jump to:  


Login
 
 
Recent Posts
Recent Topics
No new topics.
Hot Tags
Whos Online
7 Guests, 0 Users
Home Forums Contact Tags FAQ Links News Login Register