WordPress.org

Ready to get started?Download WordPress

Forums

Database driven CSS using parse_request() (2 posts)

  1. helgatheviking
    Member
    Posted 3 years ago #

    According to : http://josephscott.org/archives/2010/03/database-powered-css-in-wordpress-themes/ you can hook into the parse_request() function to get it to serve up a php file as CSS.... which would then allow you to pull CSS from a database. helpful as this is a common feature in theme options, except i can't get it to work for anything.

    i enqueue the pseudo script so that it shows up in the header

    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');

    and then my custom parse request, which i dont think ever gets called... or if it does isn't adding changing any CSS:

    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' );

    any insights will be much appreciated.

  2. Mark / t31os
    Moderator
    Posted 3 years ago #

    You might find the answer you're looking for on one of the following pages.
    How do I add CSS options to my plugin without using inline styles?
    Generating CSS Files Dynamically Using PHP Scripts?

    Hope that helps. :)

Topic Closed

This topic has been closed to new replies.

About this Topic