Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I've recently switched over from using a custom class to enable a theme options panel to the built in Theme Customizer in Wordpress.

All is going fairly well - I've got live preview working but I'm a little bit stuck on using 'get_theme_mod()' to retrieve the values in a dedicated PHP file.

Using my old class, I could enqueue 'dynamic.css.php' where I would include 'wp-load.php' to enable me to use various functions to get options etc. The Theme Customizer docs show just outputting the dynamic CSS inside a custom function in the wp_head theme. I don't really want to do it this way unless necessary.

So, I'm currently enueueing my 'dynamic.css.php' file and it looks like this:

<?php

header("Content-type: text/css; charset: UTF-8");

define( 'WP_USE_THEMES', false );
include('../../../../../wp-load.php'); ?>

@media all and (max-width: <?php echo get_theme_mod('nav-primary-breakpoint'); ?>) {

    .drawer {
        margin-top: 42px;
        padding-top: 42px;
        top: -42px;
    }

}

This is how I previously did so I attempted basically the same thing but get_theme_mod() isn't working at all.

I'm also wary of including wp-load.php again - I was hoping to use a similar methodology to before without having to actually include it.

So my aims are to:

  • avoid having to load wp-load.php
  • have my css in a separate file
  • avoid having css output my themes header

I've also tried removing the wp-load.php import and including the file in the head of my theme but this puts the output into the body tag.

Any suggestions on achieving my aims here?

share|improve this question
    
I would suggest you start with getting your AJAX right per WordPress convention: codex.wordpress.org/AJAX_in_Plugins –  s_ha_dum May 2 at 16:31

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.