A
A
Anatoly2018-07-29 04:29:38
WordPress
Anatoly, 2018-07-29 04:29:38

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(..

A couple of questions arose:
1. Should I now describe "all" styles from style.css in the head and format them through style? Or can it be done in a more elegant way?
2. In order not to contact the database every time for a color , would it be better to assign it in the functions.php itself? But then you will have to call header and footer in index.php through , is this a normal replacement for get_header()? PS. I write the "background color" parameter for simplicity, so I put a lot of things into the theme settings. 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

1 answer(s)
R
Roman Romanov, 2018-07-29
@RomanWP

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 question

Ask a Question

731 491 924 answers to any question