duanpin9531 2017-12-22 06:33
浏览 59

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

  • 写回答

1条回答

  • douao2019 2017-12-22 06:49
    关注

    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; ?>;
    }
    
    评论

报告相同问题?

悬赏问题

  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 有没有帮写代码做实验仿真的
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥30 vmware exsi重置后登不上
  • ¥15 c++头文件不能识别CDialog
  • ¥15 Excel发现不可读取的内容
  • ¥15 关于#stm32#的问题:CANOpen的PDO同步传输问题
  • ¥20 yolov5自定义Prune报错,如何解决?