Support » Plugins » Hacks » Dynamic Stylesheet and get_theme_mod() error

  • I’m having an issue while trying to use a dynamic stylesheet, mystyle.css.php, getting the error “Fatal error: Call to undefined function get_theme_mod()”

    I registered and enqueued the the stylesheet in my functions.php file, as follows:

    wp_register_style('mystyle', get_template_directory_uri() . '/bc-parts/mystyle.css.php');
    wp_enqueue_style('mystyle', get_template_directory_uri() . '/bc-parts/mystyle.css.php');

    And this is the stylesheet:

    <?php
    header('Content-type: text/css');
    ?>
    
    a:link, a:visited:link {
    	color: <?php echo get_theme_mod(site_title_color);?>;

    I’m using WordPress Customizer with Kirky plugin. My objective is to use a dynamic stylesheet rather than having all the generated styles output to the head of the theme.

    What am I missing?

    Thanks 🙂

Viewing 4 replies - 1 through 4 (of 4 total)
  • Moderator bcworkz

    (@bcworkz)

    You can’t directly request custom PHP pages in WP. You’ll see some work arounds where the requested page includes wp-load.php, but that is not a truly workable solution. This is all explained here:
    http://glennmessersmith.com/pages/wpenviro.html

    As it happens, he uses a dynamic CSS file as an example!

    Thank you, bcworkz. In my search for a solution I did find mentions of wp-load.php, and now it makes perfect sense. I realize this is not a perfect solution, as it loads way more code than what I need for a simple stylesheet, but now I can move forward with my project while I try to find a more efficient solution. Have a great day!

    I’d suggest to do it the way that they do it in the codes pages. That’s to add in a block of CSS in the <head> tags using the wp_head action. There’s no need for any outside files, no loading more resources than are required (because they’re alreayd loaed anyway), and you can easily control where the code is output by varying the $priority argument.

    Thanks for the tip, Catacaustic, but that’s exactly what I’m trying to not do. The stylesheet is really huge.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Dynamic Stylesheet and get_theme_mod() error’ is closed to new replies.