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
- How important is it to enqueue a theme’s stylesheet?
- How do I remove a pre-existing customizer setting?
- Custom Image section in Customizer
- Enqueue Stylesheets After Theme’s “rtl.css”
- Are the WordPress Core CSS styles really all nessesary?
- Any alternate TinyMCE4 themes / subthemes?
- Why I can’t add a CSS style in this WordPress theme?
- Allow Shortcode in Theme Customizer
- Theme Customizer – Nested Sections?
- 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?
- How to edit an existing WordPress theme? [closed]
- Add a preview to a WordPress Control Panel
- How to remove menus section from WordPress theme customizer
- Checking if there is an Image inserted – if not don’t display anything
- Custom CSS In Uploads Folder
- De-registering parent style sheet css recommended?
- Default header image does not display
- Responsive Images – Generating multiple images from Theme Customizer control upload?
- wordpress custom theme import and export options for sample data [closed]
- How to hook CSS file according to theme selection in the customizer section
- Custom CSS without css.php file
- WordPress not registering Theme Customization Section
- WP Customize refresh problem
- Media Uploader in custom path
- Hide header texts (Title & Tagline) in custom-header.php
- get_option in header.php not returning value from customizer
- Internal error 500 accessing Theme > Customize
- Using PIE CSS in WordPress. “localizing” styles
- How to check if a WordPress core block is active in sidebar
- How to override checkbox styles if these inputs have a unique id [closed]
- Folder name for a pro version of a WordPress.org theme?
- Display theme layouts [closed]
- Customizer: save setting/control content to post/page
- WordPress Unite Theme: Footer isn’t sticking [closed]
- Using WordPress’ Theme Customizer to select page templates that update layout in the preview
- Is accessing theme and using customizer GPL distribution?
- How to enqueue javascript for WP Customize options sidebar?
- Combining CSS files into a single cached one
- Change WordPress header color using customizer
- Default Text not showing from customizer
- How to change footer or for different kinds of users in wordpress?
- How do I remove inline style in featured image markup?
- different way to achive stylesheet_url
- How do I use a color from theme options?
- Is there any way to register custom background images like header images?
- Why is my CSS not loading?
- Ideal inline dynamic CSS injection
- How to transfer one domain to another domain without losing theme options (customizer)?
- Theme Customizer not displaying saved values in wp_head (CSS)
- JQuery undefined and Stylesheet loads in bottom along with js files
- How to allow certain PHP functions when using sanitize_callback in the word press customizer
- How can I wrap all blog posts image with
- Customizer Color Control Not Working
- where is real values of variables?
- White screen when attaching css to function.php
- How to allow users to create their own website within my domain? [closed]
- Avada Child Theme Development
- Theme customizer – can’t add section/settings
- A post with a clear:both in its css destroy the theme design, and the sidebar is moved to the bottom
- How to create a WP theme that use BootStrap? [closed]
- Tiny MCE custom styles, and preview in the backend
- .current_page_ancestor broken in Twenty Eleven
- How to add wysiwyg editor in customize screen using customize_register
- WordPress Animation Adjustments
- Is there a list of default generated Gutenberg block CSS? Unable to align video blocks
- How to copy page/post from one theme to another?
- How to change listing type permlink?
- In wordpress customizer div still showing even if I hid it with javascript
- How do I change the color of individual page titles in WordPress?
- Why does wp_customizer default values do not apply when theme is installed for the first time?
- Find the source file causing a Mixed Content warning
- How to reduce the vertical space above and below a ul list uniformly with one command?
- How Do I Create a WordPress Demo Site with Limited Admin Access
- Fatal error: Class WP_Customize_Image_Control not found
- What is difference between add_theme_support and Theme Customization API?
- How can I fix my theme header for my CSS stylesheet?
- How do I remove header/page-title image in farvis theme? [closed]
- How to show Custom Field Value in Woocommerce Shop Page
- How to display only the first two elements from ten same elements
- Duplicate child theme incl. design changes
- Necessary css classes to be included in theme stylesheet
- How to customize the colors within a stylesheet using a WordPress setting
- Correct was to customise theme using get_theme_mod in scripts
- Images use & location, on new wordpress theme
- How to create multiple customizer controls in one control
- How can I fix the even/odd child classes comments so that the comments are unaffected by the top-level even/odd?
- Setting different CSS for all pages except home.php
- How customizable is a self-hosted WordPress blog compared to a Blogger blog?
- My theme is full of error messages in the “Customize” screen, but nowhere else
- WP Customizer get control value on change
- Execute javscript when theme customizer loads (autosave issue)
- Align images to the left of the content