[wp-hackers] checking if post has shortcode, before header is output?

Aaron D. Campbell aaron at xavisys.com
Mon Oct 26 19:15:10 UTC 2009


That's true, which is why I was advocating something like this:
function myplugin_add_js () {
    wp_print_scripts( 'myplugin_myjs' );
}
function myplugin_shortcode_handler($attr, $content = '') {
    add_action( 'wp_footer', 'myplugin_add_js' );
}

That's assuming that your js is already registered using the handle 
'myplugin_myjs' and that the wp_footer action is correctly called from 
your theme.

Otto wrote:
> On Mon, Oct 26, 2009 at 12:41 PM, Aaron D. Campbell <aaron at xavisys.com> wrote:
>   
>> That still doesn't fix the case where more than one query is ran on a page,
>> when someone does something like "$myQuery = new WP_Query($params);" you'd
>> process the main query, but you wouldn't get any of the shortcodes in the
>> custom query.
>>     
>
> That's because that is not possible. You're basically wanting to know
> the content returned by the query before you ever run the query
> itself. Can't be done, because of, you know, time only traveling in
> one direction. Damn physicists.
>
> To do this sort of thing, you'd need to use output buffering. Buffer
> the whole page, then modify it after the fact, inserting what you want
> where you want.
>
> -Otto


More information about the wp-hackers mailing list