[wp-hackers] Load scripts in header only when needed

Ozh ozh at planetozh.com
Sat Nov 29 20:47:13 GMT 2008


Depends on your plugin
I'd do the following: check if the plugin does something in posts, and
if so, add_action('wp_footer','my_javascript') that would insert on
bottom of the page the needed JS

On Sat, Nov 29, 2008 at 9:30 PM, Ade Walker <photofantaisie at gmail.com> wrote:
> Very useful. I've bookmarked it for future reference. Thanks!
>
> But what about non-admin pages? How do I avoid loading the js in every
> non-admin page, given that I only want the js on pages (most likely single
> post or page.php or a page template) where the gallery is called?
>
> Thanks.
>
> 2008/11/29 Ozh <ozh at planetozh.com>
>
>> Should help :
>> <
>> http://planetozh.com/blog/2008/04/how-to-load-javascript-with-your-wordpress-plugin/
>> >
>>
>> On Sat, Nov 29, 2008 at 3:14 PM, Ade Walker <photofantaisie at gmail.com>
>> wrote:
>> > Hi all,
>> >
>> > I've probably been staring at the computer screen too long, but I'm
>> > struggling to get my head around this...
>> >
>> > I'm playing around with a new gallery plugin which uses javascript. The
>> > gallery will be called by a function call in a theme template file.
>> However,
>> > I only want to load the scripts into the header on pages that actually
>> need
>> > it.  The problem is that if I try to load the scripts into the head based
>> on
>> > the template function call it's too late - wp_head has been and gone.
>> >
>> > If anyone could point me in the right direction I'd be very grateful. :-)
>> >
>> > Thanks.
>> >
>> > Ade.
>> > _______________________________________________
>> > wp-hackers mailing list
>> > wp-hackers at lists.automattic.com
>> > http://lists.automattic.com/mailman/listinfo/wp-hackers
>> >
>>
>>
>>
>> --
>> http://planetOzh.com ~ Blog and WordPress Stuff
>> http://FrenchFragFactory.net ~ Daily Quake News
>> _______________________________________________
>> wp-hackers mailing list
>> wp-hackers at lists.automattic.com
>> http://lists.automattic.com/mailman/listinfo/wp-hackers
>>
> _______________________________________________
> wp-hackers mailing list
> wp-hackers at lists.automattic.com
> http://lists.automattic.com/mailman/listinfo/wp-hackers
>



-- 
http://planetOzh.com ~ Blog and WordPress Stuff
http://FrenchFragFactory.net ~ Daily Quake News


More information about the wp-hackers mailing list