管理页面上的Wordpress插件css

时间:2014-12-09 07:13:46

标签: css wordpress plugins

更新:我的插件css在管理区域无效。以下工作在我的网站上供公众查看,但不在我正在建设的管理页面上。

原始问题: 我正在尝试制作html文本“Make this red”,红色! 我有一个插件,我已经添加到我的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”这个句子出现在(admin)页面上,但它是黑色的。

3 个答案:

答案 0 :(得分:0)

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

是否有另一个带有&#34; .bio_btn&#34;的css文件在它?

无论如何,可能还有一个小孩骑过它。

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

CSS

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

答案 1 :(得分:0)

试试这个:

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

答案 2 :(得分:0)

解决了!对于管理页面,您必须替换&#34; init&#34;用&#34; admin_init&#34;和&#34; wp_enqueue_style&#34;用&#34; admin_enqueue_style&#34; :)