0

When i am trying to add hex color its crossed out in frontend and if i add color directly i.e. black or white it works ..how can i fix this issue.

This one does not work

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

} add_action( 'wp_enqueue_scripts', 'my_styles_method' ); ?>

But this one works

   function my_styles_method() {
wp_enqueue_style(
    'custom-style',
    get_template_directory_uri() . '/css/custom_script.css'
);
    $color = black;
    $custom_css = "
            .mycolor{
                    background: {$color};
            }";
    wp_add_inline_style( 'custom-style', $custom_css );

} add_action( 'wp_enqueue_scripts', 'my_styles_method' ); ?>

2
  • Both the codes are identical.. Am I missing something?
    – Abhik
    Jun 9 '18 at 18:20
  • sorry my mistake there is difference in $color value. Jun 9 '18 at 18:30
2

You're not setting the variables correctly. The values are strings so need to be in quotes:

$color = #FF0000 ;

Needs to be

$color = '#FF0000';
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.