Use case: content managers would have permissions to change the color scheme of the site.

Solution: I would make a page from hook_menu and give option to select from different pre defined css files.

Is there a hook/function I can use to render css files accordingly as per selected by user.

like: user selects red option the red named css file should render on site and previous, default css should be overridden.


3 Answers 3


I found the link bit helpful... It might help you too. http://wearepropeople.com/blog/7-ways-to-add-custom-js-and-css-to-a-page-in-drupal

  • While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes Sep 18, 2014 at 7:38

at the time of using hook_menu 'page callback' => 'your_php_function',

then later in function

function your_php_function(){

drupal_add_js() // check for this function in google and add your js file here

drupal_add_css() // check for this function in google and add your css file here

/* * your code goes on */


Create a specific module "custom_css" for exemple.

Use a single function custom_css_preprocess_page() https://api.drupal.org/api/drupal/includes%21theme.inc/function/template_preprocess_page/7

inside call the Global $user; get the css value form $user node and use like shrindar say, the drupal_add_css() function.

And it should work. If the red is selected, you'll charge the red CSS. Be care, you'll maybe need to flush your cache if you activated them.

Why do you want to create a custom page from hook_menu? You can in Drupal 7 add fields to the profile, each user can choose his own theme from the edit profile page.

  • Hmm ,.. Interesting... Thanks for the answer... Reason for making a page is that I don't want to give the settings to each user.. I want to create a settings page where a user with permission can change the color.
    – nitvirus
    Sep 18, 2014 at 14:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.