Roots Discourse

Styles not injected in admin/login page

Hey guys, I can’t get my styles to be injected in the login page and admin panel while the “watch” process is active.

Still new to Sage and have looked everywhere but couldn’t find an answer, thought this issue was similar to mine.

I’ve added the entry properly in my config.json:

"admin": [
    "./styles/admin.scss"
],

And then enqueue it like this…

function admin_assets() {
    wp_enqueue_style( 'theme/admin.css',  asset_path('styles/admin.css') );
}
add_action( 'admin_enqueue_scripts', __NAMESPACE__ . '\\admin_assets', 10 );
add_action( 'login_enqueue_scripts', __NAMESPACE__ . '\\admin_assets', 10 );

…which adds the stylesheet properly to the page, but as far as I understand while running the local server the styles are all injected and the CSS files are not actually created. Therefor the link to the stylesheet points to a 404 page and I’m left without my styles.

Is this actually possible? Would love some help please!
Thanks

Looks like that is your issue. Did any of the suggestions in there work (adding a JS file and enqeueing it as well)?

Fixed this temporarily by adjusting the webpack CleanPlugin config to ignore the “styles” folder. This obviously still doesn’t inject the styles in the admin dashboard and login page, but the “admin.css” stylesheet was being enqueued properly so now the styles show up.

One drawback of this is that I have to rebuild every time I change the admin.scss file but I usually work on it only once at the start of the project (to create the custom color scheme and look for the login page).

I have exactly the same issue.
My file is enqueued in fact if I change the body colour it changes on the website but it doesn’t change in the admin login page

function custom_admin_style() {
   wp_enqueue_style('sage/admin.css', asset_path('styles/admin.css'), false, null);
}
add_action('admin_enqueue_scripts',  __NAMESPACE__ . '\\custom_admin_style');
add_action('login_enqueue_scripts', __NAMESPACE__ . '\\custom_admin_style' );

It’s weird because with Sage 8 it was working fine! I need the admin to be customised for a client.

Can you explain in details please?

A quicker/easier fix might be to follow the workaround mentioned in the issue for this bug — create an admin.js file and enqueue it as well

1 Like