[wp-hackers] wp-config.php, wp-load.php, and ABSPATH
Stephen Rider
wp-hackers at striderweb.com
Wed Sep 16 14:21:02 UTC 2009
An interesting technique, and something I will definitely file for
future reference, but not really appropriate for the CSS example I
gave. Is it really the *best* way to have to have a bunch of GET
string attached to every page of a site just to customize some CSS???
Talk about ugly URLS for such a minor thing.
I think the best is to simply output the custom CSS to wp-head.
Question: Do enqueued CSS or scripts come specifically before or
after wp-head output? Is it ***definitive*** or does it depend on the
theme?
Stephen
P.S. -- In all of this, I'm not sure I've ever heard a satisfactory
explanation for WHY all these things should be enqueued anyway.
Dependencies, sure, but why for a stylesheet or script that doesn't
have any dependencies?
On Sep 15, 2009, at 9:07 AM, Otto wrote:
> Wow. Everybody else got that one wrong too. :)
>
> The right way is to not load "styles.css.php" directly in the first
> place. If you need to load the WordPress files, then you should load
> WordPress itself, and direct it to do what you want it to do.
>
> If you want to make some kind of output outside the normal "flow" of
> WordPress, but need the WordPress functions to do it:
>
> First, realize that WordPress is going to load twice anyway. The goal
> is not to eliminate this (if you need wpdb access in your separate
> file, then you sorta have to do load WP again), but to eliminate the
> need to know the WordPress file paths and such.
>
> Example code:
> function plugin_query_vars($public_query_vars) {
> $public_query_vars[] = 'SOME_IDENTIFIER';
> return $public_query_vars;
> }
> function plugin_special_output() {
> if(intval(get_query_var('SOME_IDENTIFIER')) == 1) {
> // do whatever output you like here
> exit; // stop normal WordPress execution
> }
> }
> add_filter('query_vars', 'plugin_query_vars');
> add_action('template_redirect', 'plugin_special_output');
>
>
> After you add this code, a call to any normal WordPress URL with
> ?SOME_IDENTIFIER=1 stuck on the end will return your code instead.
> That code can be *anything*. If you want to output CSS, output CSS.
> Change the headers if you like. Whatever.
More information about the wp-hackers
mailing list