Answer the question
In order to leave comments, you need to log in
How to correctly implement color change through the admin panel in Wordpress?
I decided to display the background color in the theme setting, through
add_action('customize_register', function($customizer){
$customizer->add_section(..
$customizer->add_setting('my_color1', ..
$customizer->add_control(..
get_theme_mod('my_color1')
$my_color1 = get_theme_mod('my_color1')
require('header.php')
Answer the question
In order to leave comments, you need to log in
The method is not the only one, often used in prof. topics. If there are a lot of settings related to site styles (colors, backgrounds, fonts, etc.), then you can use, for example, the Redux Framework or in the pro version of ACF it is possible to make a page with options. And we create a dynamic css file (example style-theme.css), in which all changes in styles will be recorded. And in order to get rid of unnecessary queries to the database, we save changes only if the settings in our theme have been updated. For acf, you will have to add a little code, solutions can be found on request in Google acf dynamics css or in Redux a little simpler
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question