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?