How to include CSS for a custom admin theme?
Question
I want to include my custom style.css in admin pages in Custom Admin theme I have been create.
I am including CSS in .info file as follows
name = Example Module
description = Custom Example Module
core = 7.x
configure = admin/config/example-module/settings
permissions = admin/people/permissions#module-example-module
stylesheets[all][] = css/style.css
and I used mymodule_preprocess_page(&vars)
, but I didn't see any result.
Solution
You can add yourstyl.css in admin theme's .info file. Just goto your active admin theme, find and open its .info file and place a simple line here; stylesheets[ ] = css/yourstyle.css . It works like a charm.
OTHER TIPS
When I look at your .info
file I see it is Custom Module instead Custom Theme
name = Example Module
description = Custom Example Module
core = 7.x
configure = admin/config/example-module/settings
permissions = admin/people/permissions#module-example-module
stylesheets[all][] = css/style.css
Instead adding Style to module info file add it to theme info file
in your themename.info
add stylesheets[all][] = css/style.css
I misunderstood your question. It's not about a core admin theme. It's about a custom admin theme you created. Then of course you add that CSS from your custom admin theme's .info
file.
Otherwise, if it's a core admin theme you'ld write a simple custom module or add the following to an existing custom module. All you need to implement is hook_page_build()
and then add your own CSS file with drupal_add_css()
. The important thing there is to add 'group' => CSS_THEME
as an option to prevent the styles from getting overwritten.
/**
* Implements hook_page_build().
*/
function MYMODULE_page_build(&$page) {
// check current path
if (path_is_admin(current_path())) {
// add CSS
drupal_add_css(drupal_get_path('module', 'MYMODULE') . '/css/custom_admin.css', array('group' => CSS_THEME));
}
}
Try drupal_add_css() function in your template file.