[wp-hackers] How to enqueue default scrips in footer?

Samuel Wood otto at ottodestruct.com
Sat Sep 26 11:24:08 UTC 2009


You're doing it too soon. The wp-scripts variable needs to be defined
before you call my code example. So, put it on the init action hook or
similar.

- Please excuse brevity and typos, sent from my iPhone.



On Sep 25, 2009, at 4:06 PM, Milan Dinić <liste at srpski.biz> wrote:

> Thank you for your answers. Tynan's approach still places it in
> header while
> Otto's make error (Call to a member function add_data() on a non-
> object in
> ...).
>
> Maybe I didn't describe what I want. I wanted to enqueue script in
> footer in
> frontend, not in admin.
>
> My understanding of in_footer thing was that it will load script in
> footer
> if there is no plugin/theme that call it in head, so if other plugin
> use
> standard way of enqueuning (without defining in_footer), script will
> be
> loaded in head, no matter if there are plugins which place it in
> footer.
>
> But anyway, I can't place script in footer even when only that one
> plugin is
> activated, meaning that no other plugin is enqueuning that same
> script.
>
> 2009/9/25 Otto <otto at ottodestruct.com>
>
>> For default scripts, if you want to force them to the footer when
>> they're not already:
>>
>> global $wp_scripts;
>> $wp_scripts->add_data('comment-reply', 'group', 1 );
>>
>> Then just enqueue as per normal:
>>
>> wp_enqueue_script('comment-reply');
>>
>>
>> -Otto
>>
>>
>>
>> 2009/9/25 Tynan Colin Beatty <junsuijin at gmail.com>:
>>> {{{
>>> global $wp_scripts;
>>>
>>> wp_enqueue_script(
>>>   'comment-reply',
>>>   $wp_scripts->registered['comment-reply']->src,
>>>   $wp_scripts->registered['comment-reply']->deps,
>>>   $wp_scripts->registered['comment-reply']->ver,
>>>   true // print in footer
>>> );
>>> }}}
>>>
>>> it would be nice if there was a simpler approach tho. maybe this
>>> merits a
>>> trac ticket.
>>>
>>> peace~
>>>
>>> On Fri, Sep 25, 2009 at 5:45 AM, scribu <scribu at gmail.com> wrote:
>>>
>>>> Most default scripts are included in the footer, when possible.
>>>> It's
>>>> usually
>>>> a plugin that forces jQuery, for example, to be loaded in the head.
>>>>
>>>>
>>>> On Fri, Sep 25, 2009 at 7:14 AM, Milan Dinić <liste at srpski.biz
>>>> > wrote:
>>>>
>>>>> I know how to load custom scripts but what about custom ones? (
>>>>>
>>>>>
>>>>
>> http://codex.wordpress.org/Function_Reference/wp_enqueue_script#Default_scripts_included_with_WordPress
>>>>> )
>>>>> _______________________________________________
>>>>> wp-hackers mailing list
>>>>> wp-hackers at lists.automattic.com
>>>>> http://lists.automattic.com/mailman/listinfo/wp-hackers
>>>>>
>>>>
>>>>
>>>>
>>>> --
>>>> http://scribu.net
>>>> _______________________________________________
>>>> 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
>>>
>> _______________________________________________
>> 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


More information about the wp-hackers mailing list