【问题标题】:get data from wp-option and use in style.php and include it in header as css file从 wp-option 获取数据并在 style.php 中使用并将其作为 css 文件包含在 header 中
【发布时间】:2022-01-10 02:25:25
【问题描述】:

我想为我的自定义主题创建一个选项,用户可以更改主题颜色(如导航背景)。 我想从数据库中获取一些数据,如颜色代码(#000),然后在 style.php 文件中使用。之后将其作为 css 文件包含在 wp_head 中。 问题是当我使用这段代码时:

wp_enqueue_style('style.php.css', '/functions/style.php');

我得到这个错误:

Uncaught Error: Call to undefined function theme_get_option() in D:\xampp\htdocs\theme\wp-content\themes\theme\functions\style.php:6

感谢帮助

【问题讨论】:

    标签: php css wordpress


    【解决方案1】:

    直接使用get_option()

    get_option( string $option, mixed $default = false )
    

    参数 $选项 (字符串)(必需)要检索的选项的名称。预计不会被 SQL 转义。

    $默认值 (混合)(可选)如果选项不存在,则返回默认值。

    示例 get_option('bg_color');

    另外,您可以使用此插件为您的客户创建一个选项页面 https://wordpress.org/plugins/admin-options-pages/

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-10-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多