WordPress.org

Ready to get started?Download WordPress

Forums

wp_enqueue_scripts handle not being called in plugin (2 posts)

  1. MightyDDP
    Member
    Posted 1 year ago #

    Hi guys,

    I'm new to wordpress/php/apache in general, and I'm currently creating my first plugin. I've got the plugin running fine and want to add some css in the admin section.

    The very best I've succeeded to do is to call this inside of my page:

    wp_register_style("my-style.css", PLUGIN_URL."my-style");
    wp_enqueue_style('my-style.css');

    But it loads it in the body of the page, not in the header. My guess is that I should enqueue it like this:

    add_action('wp_enqueue_scripts', 'prefix_add_style');
    function prefix_add_style() {
        wp_register_style("my-style.css", PLUGIN_URL."my-style");
        wp_enqueue_style('my-style.css');
    }

    But when I do that, the css file doesn't show up anymore in the page source code.

    I tried to provide any relevant information, but if you need more details, just ask them, I'll gladly provide them.
    Thanks for your help!

  2. coombesy
    Member
    Posted 5 months ago #

    In my experience this normally happens when the url to the style is wrong. Looking at your code it seems that the problem is probably with this line:
    wp_register_style("my-style.css", PLUGIN_URL."my-style");

    It seems maybe you should be using the plugins_url() function When this happens I try echoing the location of the stylesheet and see if it loads correctly in the browser.

Topic Closed

This topic has been closed to new replies.

About this Topic