How to cut unwanted inclusions of css and js from Drupal themes (6.x version)

    Hello, Habra-comrades!

    I often see reports that extra Drupal css inclusions (files like system.css, defaults.css, node.css) that interfere with already prepared styles and interfere with coders live peacefully in Drupal themes.

    Actually, I’ll tell you how to get rid of these inclinations correctly now (the solution is not suitable for those who, for some reason, prefer to see the admin panel in the site’s topic - don’t even start these actions !!!).

    First, open the template.php file , which is located in the desired topic.

    Then, wherever you like, add the following code (replace YOURFUNCTIONNAME with the name of your theme):

    function YOURFUNCTIONNAME_preprocess_page(&$vars) {

    if( request_uri() != '/admin/build/block' ){

    // получаем массив всех css
    $css = drupal_add_css();

    // Удаляем неугодные элементы

    // Возвращаем почищенный массив Друпалу
    $vars['styles'] = drupal_get_css($css);



    That's all - unnecessary unnecessary styles do not slow down the page loading and it is easier for your styles to find the right path to the user's eyes. The condition " if (request_uri ()! = '/ Admin / build / block') {} " is here so that on the page for editing blocks (which, although it is part of the admin panel, is still displayed in the design of the site), it remains necessary for work functional.

    Since we cut css, we’ll similarly take on JavaScript inclusions. In the same function YOURFUNCTIONNAME_preprocess_page we add:

    // Добавляем свеженький jQuery

    // Получаем массив всех JS инклудов
    $js = drupal_add_js();

    // Вырезаем неугодный старенький jQuery

    // Возвращаем Друпалу почищенный массив JS
    $vars['scripts'] = drupal_get_js('header', $js);


    This is how you can easily get rid of the regular JS jQuery call of some kind of bearded version 1.2.6 from 2008 on the main page (I needed to do a lot of complex JS on the main one, which did not work with the old version of jQuery and so I easily and simply arranged substitution).

    Be careful with cutting JS - do not ruin the functionality of Drupal :)

    That's all! I hope this is useful to someone.

    UPDATE On the advice of Anonym and Razunter, if you just want to update the jQuery version, then it is better to use a patch or jQuery Update module . Manually cutting JavaScript inclusions can cause problems.

    Also popular now: