简体   繁体   中英

WordPress Plugin ColorPicker and write in CSS file

i develop my own plugin for the first time. I have come very far, so far it works very well.

What I would like to program this time is a, color picker. This Color Picker, should change the HEX code in my CSS file.

I already have a color picker in my backend, but how can I program a function now, where I say, write this into the CSS file in the classe.

I hope you have understood my problem. Now you have to save the HEX code somewhere.

Translated with www.DeepL.com/Translator (free version)

You can use the wp_add_inline_style function:

function my_styles_method() {
    wp_enqueue_style('custom-style', get_template_directory_uri() . '/css/custom_script.css');
    $color = get_theme_mod( 'my-custom-color' ); // #FF0000
    $custom_css = "
        .mycolor{
            background: {$color};
        }";
    wp_add_inline_style( 'custom-style', $custom_css );
}
add_action( 'wp_enqueue_scripts', 'my_styles_method' );

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM