Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save bappi-d-great/208d06bc3139f2076074 to your computer and use it in GitHub Desktop.
Save bappi-d-great/208d06bc3139f2076074 to your computer and use it in GitHub Desktop.
How to write dynamic css in a php file in wordpress
<!-- functions.php -->
<?php
add_action( 'wp_enqueue_scripts', 'theme_custom_style_script', 11 );
function theme_custom_style_script() {
wp_enqueue_style( 'dynamic-css', admin_url('admin-ajax.php').'?action=dynamic_css', '', VERSION);
}
add_action('wp_ajax_dynamic_css', 'dynamic_css');
add_action('wp_ajax_nopriv_dynamic_css', 'dynamic_css');
function dynamic_css() {
require( get_template_directory().'/assets/css/custom.css.php' );
exit;
}
?>
<!-- custm.css.php file -->
<?php
header( "Content-type: text/css; charset: UTF-8" );
global $lts;
?>
body{
color: <?php echo $lts['base-color'] ?>;
}
@masweb
Copy link

masweb commented Mar 8, 2015

no va

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment