-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 ..

2
  • 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 Commented Dec 22, 2017 at 6:42
  • Related: stackoverflow.com/questions/43689560/… Commented Oct 6, 2022 at 9:02

1 Answer 1

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

1 Comment

Some more great examples of implementation: css-tricks.com/css-variables-with-php

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.