admin管理员组

文章数量:1317742

I built a module with custom CSS. I'm not sure why the CSS isn't being applied, although it seems like the page is loading the CSS file (when I view source in a page, I can see my custom CSS file, and when I open that link, the content is what it should be). The div class name is pretty custom, so I don't think it's being overwritten.

Code in module:

    function hbc_comicCanvas() {
        wp_register_style('hbc_comicCanvas', plugins_url('css/hbc_comicCanvas.css',__FILE__));
        wp_enqueue_style('hbc_comicCanvas');
        wp_register_script( 'hbc_comicCanvas', plugins_url('js/comicCanvas.js', __FILE__));
        wp_enqueue_script('hbc_comicCanvas');
    }

    add_action( 'admin_init','hbc_comicCanvas');

    function insert_default_content($content) {
        $content = "
      <div id=\"hbc_drawingPanel\">drawingPanel id</div>
        <div class=\"hbc_drawingPanel\">drawingPanel class</div>
        <canvas style='height:500px;width:500px'>woot</canvas>
        ";

        return $content;
    }
    add_filter( 'default_content', 'insert_default_content');

And the content of the CSS file:

    div #hbc_drawingPanel{
      background-color: purple;
    }
    div .hbc_drawingPanel{
      background-color: purple;
    }

Thanks for any help. I've looked at a bunch of suggestions, but nothing has panned out so far.

I built a module with custom CSS. I'm not sure why the CSS isn't being applied, although it seems like the page is loading the CSS file (when I view source in a page, I can see my custom CSS file, and when I open that link, the content is what it should be). The div class name is pretty custom, so I don't think it's being overwritten.

Code in module:

    function hbc_comicCanvas() {
        wp_register_style('hbc_comicCanvas', plugins_url('css/hbc_comicCanvas.css',__FILE__));
        wp_enqueue_style('hbc_comicCanvas');
        wp_register_script( 'hbc_comicCanvas', plugins_url('js/comicCanvas.js', __FILE__));
        wp_enqueue_script('hbc_comicCanvas');
    }

    add_action( 'admin_init','hbc_comicCanvas');

    function insert_default_content($content) {
        $content = "
      <div id=\"hbc_drawingPanel\">drawingPanel id</div>
        <div class=\"hbc_drawingPanel\">drawingPanel class</div>
        <canvas style='height:500px;width:500px'>woot</canvas>
        ";

        return $content;
    }
    add_filter( 'default_content', 'insert_default_content');

And the content of the CSS file:

    div #hbc_drawingPanel{
      background-color: purple;
    }
    div .hbc_drawingPanel{
      background-color: purple;
    }

Thanks for any help. I've looked at a bunch of suggestions, but nothing has panned out so far.

Share Improve this question edited Oct 26, 2020 at 21:39 Tom J Nowell 61k7 gold badges79 silver badges148 bronze badges asked Oct 26, 2020 at 14:04 Trevor NewhookTrevor Newhook 1012 bronze badges 4
  • Why are you using wp_normalize_path? Also how is the register and enqueue code being called? If you registered the style you don't need the extra parameters in wp_enqueue just the handle/first parameter like the docs say. That's also not how add_filter works, add_filter expects a function/callable or the name of a function as the second paramter – Tom J Nowell Commented Oct 26, 2020 at 15:19
  • You shouldn't be using it, wp_enqueue and wp_register script and style functions expect a URL, and URLs are always /. Likewise, in PHP you can use / and it will work everywhere, not just Linux TLDR always use / even on Windows. Also code in comments doesn't work, can you edit your question to include that code? Note that's still not how filters work, filters always return something, basic beginners filters 101. Right now your code should be generating lots of PHP warnings and errors, and your CSS won't have anything to work on because of the incorrect use of filters – Tom J Nowell Commented Oct 26, 2020 at 17:01
  • Also, you didn't answer my question about how your enqueue functions are being called, this is super important information, you need to share it – Tom J Nowell Commented Oct 26, 2020 at 17:04
  • 1 I updated the question. Hopefully included the info you need. Appreciate the help. – Trevor Newhook Commented Oct 26, 2020 at 18:34
Add a comment  | 

1 Answer 1

Reset to default 0

The solution was to remove wp_normalize_path

本文标签: pluginsApplying module CSS to page