在php文件wordpress变量访问上使用css样式

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

dongpiao1983
dongpiao1983 我想访问存储在数据库中的颜色数据,我想存储在$color变量中并使用数据库存储的颜色,所以我可以使用样式,php文件我在这个文件上加入内联css
2 年多之前 回复

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; ?>;
}
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问