M
M
Mikhail Lebedev2021-07-31 17:14:57
WordPress
Mikhail Lebedev, 2021-07-31 17:14:57

Changing the color of some divs to the same as body.custom-background?

I change the background color in the theme using wp-admin/customize.php in the WP console
. After that, the body has an additional class body.custom-background.
How can I now apply this color to some more divs in this theme?

I tried to add this class via

const element = document.querySelector('.site-title');
element.classList.add('custom-background');

but it doesn't work like that

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vladimir Brumer, 2021-07-31
@zaza41rus

Question - how?

... apply this color to some more divs in this theme?

like this for example

add_action('wp_head','div_style');
if(!function_exists('div_style')){function div_style(){?>
<style id="div_style" type="text/css">
  .div_style{background-color:#<?php echo get_theme_mod('background_color');?>;}
</style>
<?php }}

...............или...............

add_action('get_footer','div_style');
if(!function_exists('div_style')){function div_style(){?>
<style id="div_style" type="text/css">
  .div_style{background-color:#<?php echo get_theme_mod('background_color');?>;}
</style>
<?php }}

разметка:
61056a6bd397e579325361.jpeg

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question