0

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)

1 Answer 1

1

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' );
Sign up to request clarification or add additional context in comments.

3 Comments

How can I link this to a Color Picker? In the backend there must be the option with color picker and save. Thank you in advance!
It's depends how are you using settings storage: )
I have a database table :-)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.