Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Hello there,
I'm trying to add css in hook_init() for my module.
drupal_add_css(drupal_get_path('module', 'dropcap') .'/dropcap.css');
It doesn't get added.
Turns out, at the theme level, I have another CSS file called dropcap.css. When I give my stylesheet a unique name the stylesheet is added.
drupal_add_css(drupal_get_path('module', 'dropcap') .'/dropcapstyle.css');
Comments
Comment #1
brahmjeet789 CreditAttribution: brahmjeet789 commentedHello there,
If you created css file with the same name is not refected on site, because it create confusion for theme system which file will be implemented? so it is better to use file with different name or added your css into same css file. May be this will help you.
Thanks,
Comment #2
dcam CreditAttribution: dcam commentedSee the drupal_get_css() API documentation:
So this behavior is intentional. If you want to avoid collisions then you must rename your stylesheets.
Comment #4
koosvdkolk CreditAttribution: koosvdkolk commentedWhen using third-party libs, its not always possible to (easily) rename those CSS (and JS) files.
Please check the 'basename' property in drupal_add_css.
Comment #5
phuocdv CreditAttribution: phuocdv as a volunteer and commentedThanks