【问题标题】:Wordpress plugin css on admin page管理页面上的 Wordpress 插件 css
【发布时间】:2015-02-07 00:19:30
【问题描述】:

更新:我的插件 css 在管理区域中不起作用。以下适用于我的网站供公众查看,但不适用于我正在构建的管理页面。

原始问题: 我正在尝试使 html 文本“使这个红色”,红色! 我有一个插件已添加到我的 Wordpress 插件文件夹中。在名为“plugin.php”的文件中的“bio-plugin”文件夹中,我有以下代码:

function register_bio_style(){
    wp_register_style('bio-style',plugins_url('css/bio-style.css',__FILE__), false, '1.0.0', 'all');
}
add_action('init','register_bio_style');

function enqueue_bio_style(){
    wp_enqueue_style( 'bio-style' );
}
add_action('wp_enqueue_scripts', 'enqueue_bio_style');

然后我有这个 html 工作:

<div class='bio_btn'>Make this text red</div>

然后我将 bio-style.css 放在一个名为 css 的文件夹中,该文件夹与 plugin.php 位于同一目录中

bio-style.css 代码为:

.bio_btn{
color: red;
background: black;
}

“Make this red”这句话出现在(管理)页面上,但它是黑色的。

【问题讨论】:

  • 检查bio-style.css是否正确链接
  • 用 firebug 检查 css 和 class 调用是否正确?
  • 尝试将其更改为../css/bio-style.css/css/bio-style.css
  • 我在页面源代码中找不到 bio-style.css 链接?
  • ../css 和 /css 都不起作用

标签: css wordpress plugins


【解决方案1】:

我不能在这里发表评论,所以我只想在这里做一个半盲的回答。

是否还有另一个带有“.bio_btn”的css文件?

无论如何,可能有一个儿童 css 在骑它。

这是一个不好的方法,但它可能会起作用

CSS

.bio_btn{
color: red !important;
background: black;
}

【讨论】:

  • 这也不起作用,它没有链接css文件。页面源中没有加载 css 文件
【解决方案2】:

试试这个:

    <?php 
    /*
    Plugin Name: Bio
    Plugin URI: URL of site
    Description: Custom Plugin
    Version: 1.0.0
    Author: Rohil
    Author URI: URL of author
    */

        // Register the style like this for a plugin:
        wp_register_style( 'biocss', plugin_dir_url( __FILE__ ) . 'css/bio-style.css' );


        // For either a plugin or a theme, you can then enqueue the style:
        wp_enqueue_style( 'biocss' );



    ?>

    <div class='bio_btn'>Make this text red</div>

【讨论】:

    【解决方案3】:

    解决了!对于管理页面,您必须将“init”替换为“admin_init”,将“wp_enqueue_style”替换为“admin_enqueue_style”:)

    【讨论】:

      猜你喜欢
      • 2019-03-07
      • 1970-01-01
      • 2017-09-19
      • 2012-03-05
      • 1970-01-01
      • 2018-03-01
      • 2014-08-08
      • 1970-01-01
      • 2011-02-22
      相关资源
      最近更新 更多