【问题标题】:Adding css to the front-end via plugin and variable通过插件和变量将 css 添加到前端
【发布时间】:2017-12-09 23:39:08
【问题描述】:

好的,我不太确定该怎么做,所以也许有人可以帮助我。

我正在尝试在我的插件中创建一个函数,该函数调用要在网站前端使用的 CSS。听起来很简单……但有一个问题。

我希望能够调用从数据库输出 CSS 样式的 PHP 文件(插件保存的变量),而不是调用 CSS 文件。

例如……标准方法:

<?php

function register_style(){
    wp_register_style( 'front_stylesheet', plugins_url( '/css/custom.css', __FILE__ ) );
    wp_enqueue_style( 'front_stylesheet' );
}
add_action( 'enqueue_scripts', 'register_style' );

?>

但我知道我不能简单地将“/css/rs.css”更改为 PHP 文件路径。那么我该如何引用那个 PHP 文件呢?

PHP 文件基本上只是一个简单的页面,它从数据库中获取 CSS 样式并输出该内容“没有 STYLE 标签,因为标签已经回显。

任何帮助将不胜感激。

【问题讨论】:

    标签: php css database wordpress plugins


    【解决方案1】:

    您可以使用您所说的 register_style 方法正常添加文件,路径为“/css/custom.php”,并在生成css的custom.php文件顶部添加:

    header("Content-type: text/css");
    

    这必须是文件的第一行,前面没有空格。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-03-27
      • 2011-10-15
      • 1970-01-01
      • 2012-06-09
      • 1970-01-01
      • 2010-11-28
      相关资源
      最近更新 更多