0
votes

following the tutorial at http://josephscott.org/archives/2010/03/database-powered-css-in-wordpress-themes/ i am trying to use wordpress' parse_request function to add some php-driven CSS... mostly style options set in my theme's options panel. i am aware that my code looks a little different from the author's, but i tried it his way already. i can add the

function kia_wp_head() {
  wp_enqueue_style('dynamic', get_bloginfo('stylesheet_directory') . '/admin/ . '?my-custom-content=css');
}
add_action('wp_print_styles', 'kia_wp_head');
//this shows up properly enqueued but when i click on it in source it just brings up a directory listing for the admin folder


function my_custom_wp_request( $wp ) {
    if( isset($_GET['my-custom-content']) && $_GET['my-custom-content'] == 'css'  ) {

        # get theme options
        header( 'Content-Type: text/css' ); ?>

body {
    background-color: <?php echo 'red'; ?>
}

<?php
        exit;
    }
}
add_action( 'parse_request', 'my_custom_wp_request' );

but since the background never turns red, I am either not implementing this properly or the tutorial is missing a critical step. i've also tried the other method of putting the dynamic css in its own custom-css.php file, which is my ultimate goale, but i was just trying to see if i could interact with the parse request function properly:

function my_custom_wp_request( $wp ) {
    if (
        isset($_GET['my-custom-content'])
        && $_GET['my-custom-content'] == 'css'
    ) {
        # get theme options
        header( 'Content-Type: text/css' );
        require dirname( __FILE__ ) . '/custom-css.php';
        exit;
    }
}
add_action( 'parse_request', 'my_custom_wp_request' );

here i'm not sure what dirname( FILE ) means exactly, but i have also tried using a hardcoded path and that didn't work either.

so how do i get parse_request to see my php-driven stylesheet?

/* EDIT FOR SOLUTION */

basically this doesn't work w/ wp_enqueue_style

wp_enqueue_style('dynamic', get_bloginfo('stylesheet_directory') . '/admin/ . '?my-custom-content=css');

but DOES work as described at josephscott.org by inserting the style tag directly into the head

. '/admin?my-custom-content=css">
1

1 Answers

0
votes

i found that it doesn’t work w/ wp_enqueue_script. it does work as written in the tutorial by manually adding the script tag to the header.