Gmail Calendar Documents Reader Web more »
Recently Visited Groups | Help | Sign in
Google Groups Home
questions on best practices for wp_enqueue_script and wp_enqueue_style
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  4 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Michael Toppa  
View profile  
 More options Apr 6, 8:27 am
From: Michael Toppa <pub...@toppa.com>
Date: Mon, 06 Apr 2009 08:27:34 -0400
Local: Mon, Apr 6 2009 8:27 am
Subject: [wp-hackers] questions on best practices for wp_enqueue_script and wp_enqueue_style
Hi all,

Mike Toppa here - I'm a new member to the list. I'm trying to figure out
a couple things relating to wp_enqueue_script and wp_enqueue_style. I've
looked at a few different blog posts people have written trying to
explain these, and I'm finding incorrect advise (for example, calling
them with wp_print_scripts is not a good idea).

1. I know to wrap calls to them in my own function. To use them outside
the admin pages, what is the best action to call my function from? The
codex says to use the init action, but that causes them to also load in
the admin pages, which is undesirable. What is the best action hook to
use so that they'll load in the public pages but not the admin pages? I
came across a couple support threads with people suggesting the use of
template_redirect, but that struck me as an odd choice (even if works,
it doesn't seem like a conceptual fit).

2. Both functions want the src path defined from the root of the
wordpress installation. PLUGINDIR seems to do the trick for the plugin
directory. What is the equivalent for the active theme directory?
TEMPLATEPATH gives the absolute path, and get_stylesheet_directory_uri()
gives the absolute URL. How do I get the relative path? In my plugin I
give users the option of customizing the plugin's css and placing a copy
in their active theme folder, so I can't extrapolate the path from the
location of my script.

I'll be happy to update the codex with the correct answers if anyone
knows them.

Thanks very much,

Mike T
_______________________________________________
wp-hackers mailing list
wp-hack...@lists.automattic.com
http://lists.automattic.com/mailman/listinfo/wp-hackers


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
scribu  
View profile  
 More options Apr 6, 10:10 am
From: scribu <scr...@gmail.com>
Date: Mon, 6 Apr 2009 17:10:38 +0300
Local: Mon, Apr 6 2009 10:10 am
Subject: Re: [wp-hackers] questions on best practices for wp_enqueue_script and wp_enqueue_style
1. About using template_redirect:

DD32:

[template_redirect] is one of the easiest filters to use after WP has loaded
and parsed everything, and is ready to start outputting. when this action
fires, Plugins have everything at their disposal, and the theme hasnt
displayed anything yet, Very useful time to inspect and redirect if need be,
or to enqueue stuff that'll be needed (since you can see the posts now)

 2. You can use get_bloginfo('template_url').

--
http://scribu.net
_______________________________________________
wp-hackers mailing list
wp-hack...@lists.automattic.com
http://lists.automattic.com/mailman/listinfo/wp-hackers


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Nathan Rice  
View profile  
 More options Apr 7, 3:10 pm
From: Nathan Rice <ncr...@gmail.com>
Date: Tue, 7 Apr 2009 15:10:10 -0400
Local: Tues, Apr 7 2009 3:10 pm
Subject: Re: [wp-hackers] questions on best practices for wp_enqueue_script and wp_enqueue_style
Mike,

1. In your function, just do a conditional:
if(!is_admin()) {
wp_enqueue_script...

}

2. the src wants a url, not a path (I think). Yes, it could be a relative
url, but that can be determined based on the location of the file you're
using to do the wp_enqueue_script in (../../file.js or something similar).
But really, the full url should work fine, and will probably be your best
bet.

Nathan

My Website
http://www.nathanrice.net/

My Twitter
http://twitter.com/nathanrice

_______________________________________________
wp-hackers mailing list
wp-hack...@lists.automattic.com
http://lists.automattic.com/mailman/listinfo/wp-hackers

    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Stephen Rider  
View profile  
 More options Apr 9, 11:21 pm
From: Stephen Rider <wp-hack...@striderweb.com>
Date: Thu, 9 Apr 2009 22:21:19 -0500
Local: Thurs, Apr 9 2009 11:21 pm
Subject: Re: [wp-hackers] questions on best practices for wp_enqueue_script and wp_enqueue_style

On Apr 6, 2009, at 7:27 AM, Michael Toppa wrote:

> 2. Both functions want the src path defined from the root of the  
> wordpress installation. PLUGINDIR seems to do the trick for the  
> plugin directory.

No -- PLUGINDIR is obsolete and problematic.  use WP_PLUGIN_DIR and  
WP_PLUGIN_URL instead.

<http://striderweb.com/nerdaphernalia/2008/09/hit-a-moving-target-in-y...
 >

Stephen

--
Stephen Rider
http://striderweb.com/

_______________________________________________
wp-hackers mailing list
wp-hack...@lists.automattic.com
http://lists.automattic.com/mailman/listinfo/wp-hackers


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »

Create a group - Google Groups - Google Home - Terms of Service - Privacy Policy
©2009 Google