-2

hi guzz i am create wordpress plugin and i want to access php variable on css style i include 'style.php' file and i want to access php style variable on this file but how , my php code

<?php 

   function my_style_render(){
        // mystyle file load
        wp_enqueue_style('mystyle', MY_PLUGIN_URL."/css/my_style.css");

        $color = '#149382';
        ob_start();
        include MY_PLUGIN_PATH . '/css/style.php';
        $custom_css = ob_get_clean();
        wp_add_inline_style( 'mystyle', $custom_css );

    }

?>

//and my style.php file

.model_inline {
    background-color: {$color};
}

but color in not apply on 'model_inline' class ... anyone suggestion ..

Narayan
  • 1,670
  • 1
  • 19
  • 37
xhander meck
  • 35
  • 1
  • 2
  • 9
  • i want access data of color that store in database and i want to store in $color variable and use database stored color so i can use style,php file i accecc inline css on this file – xhander meck Dec 22 '17 at 06:42
  • Related: https://stackoverflow.com/questions/43689560/right-way-for-pass-variable-php-to-css-in-wordpress – Jesse Nickles Oct 06 '22 at 09:02

1 Answers1

1

You can try following code.

For eg:

In HTML: You can call css file like this.

<link rel="stylesheet" type="text/css" href="style.php" />

in style you can add this code. Style.php

<?php
header('Content-type: text/css');
$var = /*Get the background color*/;
?> 
.wrap{
    background-color:<?php echo $var; ?>;
}
developerme
  • 1,845
  • 2
  • 15
  • 34