[wp-hackers] checking if post has shortcode, before header is output?
jer at simianuprising.com
Mon Oct 26 18:28:58 UTC 2009
On Mon, Oct 26, 2009 at 1: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 a logical point but I suspect that in the majority of cases
people are using extra queries to show only parts of other content,
headlines or excerpts, rather than the actual the_content(). In these
cases checking the extra queries will actually cause the js to be
loaded way more often than desired. If 1/5 articles needs the JS and
you have 10 "related" headlines visible in each single.php view then
the likelihood that one of the headlines is a post that *would* need
the js is very high, and you'll be constantly loading it even though
the headlines have no use for it.
If you do show extra loops with full content (or you need this to work
on indexes/archives that show multiple posts with full content) then
+1 for the idea of adding the js to the footer. I believe there's a
hook on 'the_post' that would work pretty well to identify posts that
get displayed, though if its not too late the_content() would be
ideal, as it would only account for posts who's full content ( and
thus expanded shortcodes ) are displayed.
Jeremy Clarke | http://jeremyclarke.org
Code and Design | globalvoicesonline.org
More information about the wp-hackers