• Resolved studio1337

    (@studio1337)


    Hey folks,

    I’m having this weird issue, and I’m hoping someone has some insight into what the problem might be.

    I’m trying to add a style sheet to our admin panel. I’ve done this successfully on a few sites, but lately code I’ve been using is failing.

    This is what I’m inserting into our functions.php file:

    // ADD CUSTOM STYLES TO ADMIN DASHBOARD
    function registerAdminCss() {
    	wp_register_script('adminCss', '/bin/themes/custom/admin.css');
    	wp_enqueue_style('adminCss', '/bin/themes/custom/admin.css', array(), false, false);
    }
    add_action('admin_head', 'registerAdminCss');

    And this is what’s being output into the dashboard (domain name removed):

    <link rel='stylesheet' id='adminCss-css' href='https://www.domain.com/bin/themes/customadmin.css?ver=4.6.1' type='text/css' media='' />

    There are two issues:
    1) The slash is missing here: “custom/admin.css” (note that the output code shows “customadmin.css”
    2) I expected this would place the file into the <head></head>, since we’re hooking it into admin_head, but it’s actually placed at the bottom of the source code.

    Issue #2 isn’t a big problem. The style sheet will (probably) still work. But it’s never going to work with the URL being output incorrectly.

    What am I not seeing here? Any help would be most appreciated!

Viewing 4 replies - 1 through 4 (of 4 total)
  • That missing “/” is really odd.

    You might give the following a try to see if it fixes it:

    
    // ADD CUSTOM STYLES TO ADMIN DASHBOARD
    function registerAdminCss() {
      if (is_admin()) {
    	wp_register_script('adminCss', get_stylesheet_directory_uri() . '/admin.css');
    	wp_enqueue_style('adminCss');
      }
    }
    add_action('init', 'registerAdminCss');
    

    Try this:

    function registerAdminCss() {
            wp_register_style( 'custom_wp_admin_css', get_template_directory_uri() . '/admin.css', false, '1.0.0' );
            wp_enqueue_style( 'custom_wp_admin_css' );
    }
    add_action( 'admin_enqueue_scripts', 'registerAdminCss' );
    • This reply was modified 8 years, 5 months ago by Nikodemsky.
    Thread Starter studio1337

    (@studio1337)

    Thanks guys. I tried the version from Nikodemsky and it worked perfectly. linux4me2 – yours may have worked as well, but I stopped trying when I had it working ??

    I’m still befuddled by the dropped slash. I’m not sure if that’s a bug or what the issue might be. But I’m happy to have it sorted. Much appreciated!

    I’m glad you got it working. Yeah, that dropped slash is really bizarre. If you ever figure out why that happened, I’d like to know.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Enqueued CSS – link output drops a slash?’ is closed to new replies.