Setting up a css.php
for this purpose is overkill (or undesirable in any case, as @MarkKaplun states in the other answer).
The smoothest way for previews of css is using jquery (see part 3 of the customizer API).
Since you’re not using the transport
argument in your setting, the page is reloaded anyway, so you can simply add the styles in your functions.php
using wp_add_inline_style
, inside the function that enqueues your style.css
. Like this:
add_action ('wp_enqueue_scripts','wpse242256_add_styles');
function wpse242256_add_styles () {
wp_enqueue_style('main-style', get_template_directory_uri() . '/style.css');
$custom_css="
.im_header { background-color: " . get_theme_mod('im_header_bcolor') . '; }
.im_nav_bar { background-color: ' . get_theme_mod('im_nav_bar_bcolor') . '; }
';
wp_add_inline_style ('main-style', $custom_css);
}
Related Posts:
- Editing the custom background CSS
- Modify the Additional CSS section (adding a disclaimer)
- How to add styles set by user in the customizer
- How to disable wordpress from overload my stylesheet styles with customizer styles
- Customize Option Framework
- Default customizer colors aren’t displayed outside of the preview
- WordPress Customization API overwrite LESS variable
- WordPress 6.4.2 – can’t load editor style css using ‘after_setup_theme’ or ‘admin_init’ actions
- How to define and link full path to css located at a random folder on header.php
- How To extend WP_Customize_Control
- How to add CSS class to custom logo?
- How to add custom css file in theme?
- How important is it to enqueue a theme’s stylesheet?
- CSS not updating in browser when I change it
- How do I remove a pre-existing customizer setting?
- Solutions for generating dynamic javascript / CSS
- Do I actually need to link my theme’s style.css in the theme files
- Enqueue a stylesheet for login page and make it appear in head element
- Theme customizer – settings order
- CSS classes for theme
- Custom Image section in Customizer
- Get entered value of customiser field for live preview
- Generating CSS Files Dynamically Using PHP Scripts?
- How to remove the Theme Customization Button from the dashboard and themes options page?
- Enqueue Stylesheets After Theme’s “rtl.css”
- Is it possible ( or advisable) to allow open access to the new theme customizer for potential clients?
- Are the WordPress Core CSS styles really all nessesary?
- Add a dropdown to theme customizer
- Understanding wp_add_inline_style
- Any alternate TinyMCE4 themes / subthemes?
- Splitting WordPress theme CSS into multiple files, good or bad?
- Hide a div that is part of all pages on one specific page
- Theme Customizer : how to create multiple-level panel
- Why I can’t add a CSS style in this WordPress theme?
- Allow Shortcode in Theme Customizer
- Theme Customizer – Nested Sections?
- Customizer Active Callback not working
- Can’t get staging site to display same way as live site. Completely stumped
- How to make a theme with more than one CSS file?
- Can I create customizer setting that can handle plugin shortcode?
- How to execute conditional script when on new customize.php (Theme Customize) screen
- Is the theme customizer slowing down my site?
- Trigger Customizer saving process with Javascript only
- Adding customizer styles with wp_add_inline_style
- How to edit an existing WordPress theme? [closed]
- Suggestions for creative use of post format feature, or themes that use them well
- Add class to before_widget for all widgets with a dropdown and a counter
- Why max-width:97.5% on content images?
- add generated stylesheet from parent theme after child-themes style.css
- Add a preview to a WordPress Control Panel
- WordPress Customizer Typography: How to load just the unique Google Fonts?
- WordPress Customize — Move “menus” options / field to another section
- Can we add more than one control under a setting in WP theme customizer?
- Widgets panel not displaying in the Theme Customizer
- use add_action(‘wp_head’) in a widget for generating dynamic CSS styles
- why does twenty eleven theme mix up the css measurement units?
- Setting up partial Right-to-Left admin interface
- Adding inline styles from a widget
- Can’t edit style.css in subdirectory of my theme?
- Adding dashicon fonts to the admin of pre 3.8 installs
- Is it possible to display the admin bar while in the Theme Customizer?
- How to Handle CSS for Multiple Header header.php Files?
- How do I get a parent theme modification from a child theme?
- Changing the entire control choices using wp.customize with JavaScript
- How to Change CSS Variable value in Theme Customizer Live Preview
- CSS in child theme not overriding the parent theme [closed]
- How to remove menus section from WordPress theme customizer
- How to add (css) classes to only one wp_nav_menu()?
- Get background color for Live Preview with Theme Customization API?
- Adding dashicon fonts to the admin of pre 3.8 installs
- Move my theme style.css into a folder
- Convert a static website to a WordPress theme and import all existing content
- How to keep theme layout the same when admin gray bar is present?
- Enqueued Stylesheets Effecting Admin Styles
- Checking if there is an Image inserted – if not don’t display anything
- Custom CSS In Uploads Folder
- There’s an image named g.gif somewhere in my WordPress site
- wp_head() not inserting the default stylesheet style.css
- How to highlight the current page in the nav menu?
- “Display Site Title and Tagline” checkbox not working?
- Writing Clean WooCommerce Styles
- First completely customized theme, where should I start?
- Root Sage theme styles are not working!
- How to set page template on front using starter content?
- De-registering parent style sheet css recommended?
- Default header image does not display
- Whats the safest way to output custom JavaScript and Css code entered by the admin in the Theme Settings?
- WordPress Customizer Control with React
- Alterntives to BEM syntax that comply with WordPress coding standards? [closed]
- Responsive Images – Generating multiple images from Theme Customizer control upload?
- Modify Javascript Configuration Options for Theme Customizer Colour Picker
- How to change the customizer´s sidebar width?
- Theme Customizer – Choose where widget area appears, to let users organise widgets
- Sub folder CSS that’s read by Admin panel
- WordPress 5.8 update problem custom theme styles are overridden by core styles common.min.css
- wordpress custom theme import and export options for sample data [closed]
- How to hook CSS file according to theme selection in the customizer section
- WordPress default theme css units
- How i can get widgets areas working in customizer?
- How Can I Create a List of Values to Be Iterated Through via WordPress Customization API?