[wp-testers] Enqueue script if shortcode exist

Lox lox.dev at knc.nc
Sun Jun 6 15:45:08 UTC 2010


Thks guys. I will use that method.

But I think that this footer script should be added to Twenty Ten theme, so
that plugin developers can make use of that feature and thus prevent useless
loading of scripts on every page.

Le 7 juin 2010 00:07, "Dion Hulse (dd32)" <wordpress at dd32.id.au> a écrit :
> Ah! I forgot about the footer param, thats definately the way to go
>
> On Sun, 06 Jun 2010 22:57:23 +1000, John Blackbourn
> <johnbillion+wp at gmail.com <johnbillion%2Bwp at gmail.com>> wrote:
>
>> It can be done by placing wp_enqueue_script() inside your shortcode
>> function, but it requires more than Alex's example.
>>
>> First, you have to set the 'in_footer' parameter of
>> wp_enqueue_script() to true, so the script is queued in the footer.
>> Then, you have to manually call wp_print_scripts() in the WordPress
>> footer so the script is output.
>>
>> Scribu wrote a good tutorial on this subject actually:
>> http://scribu.net/wordpress/optimal-script-loading.html
>>
>> John
>>
>> On Sun, Jun 6, 2010 at 1:37 PM, Dion Hulse (dd32) <wordpress at dd32.id.au>
>> wrote:
>>> That will not work.
>>>
>>> Shortcodes are parsed too late, as in, They're passed when the content
>>> is
>>> being displayed, which is after the headers have been sent.
>>>
>>> The only available method right now, is in wp_head hook, scan
>>> $posts[1....$count]->post_content for your shortcode and
>>> wp_enqueue_script()
>>> your script then AFAIK
>>>
>>> On Sun, 06 Jun 2010 21:47:38 +1000, Alex Hempton-Smith
>>> <hempsworth at gmail.com> wrote:
>>>
>>>> Bear in mind wp-hackers is probably a better list for this question.
>>>>
>>>> If you want jquery to be enqueued when a specific shortcode is
>>>> included,
>>>> just have it within the shortcode function:
>>>>
>>>> function myshortcode_func(){
>>>> wp_enqueue_script('jquery');
>>>> echo 'jQuery has been enqueued!';
>>>> }
>>>> add_shortcode('myshortcode', 'myshortcode_func');
>>>>
>>>> -- Alex (Hempsworth)
>>>>
>>>>
>>>> On Sun, Jun 6, 2010 at 7:36 AM, Lox <lox.dev at knc.nc> wrote:
>>>>
>>>>> Hello,
>>>>>
>>>>> I need to enqueue jquery when a specific shortcode is found in a page.
>>>>> Has such a feature been implemented in 3.0 ?
>>>>>
>>>>> --
>>>>> Lox
>>>>> lox.dev at knc.nc
>>>>> _______________________________________________
>>>>> wp-testers mailing list
>>>>> wp-testers at lists.automattic.com
>>>>> http://lists.automattic.com/mailman/listinfo/wp-testers
>>>>>
>>>> _______________________________________________
>>>> wp-testers mailing list
>>>> wp-testers at lists.automattic.com
>>>> http://lists.automattic.com/mailman/listinfo/wp-testers
>>>>
>>>
>>>
>>> --
>>> Dion Hulse / dd32
>>> Contact:
>>> e: contact at dd32.id.au
>>> Web: http://dd32.id.au/
>>> _______________________________________________
>>> wp-testers mailing list
>>> wp-testers at lists.automattic.com
>>> http://lists.automattic.com/mailman/listinfo/wp-testers
>>>
>> _______________________________________________
>> wp-testers mailing list
>> wp-testers at lists.automattic.com
>> http://lists.automattic.com/mailman/listinfo/wp-testers
>>
>
>
> --
> Dion Hulse / dd32
> Contact:
> e: contact at dd32.id.au
> Web: http://dd32.id.au/
> _______________________________________________
> wp-testers mailing list
> wp-testers at lists.automattic.com
> http://lists.automattic.com/mailman/listinfo/wp-testers


More information about the wp-testers mailing list