Drupal 6 & 7 unset Javascript from header -
edit: question applies drupal 6 & 7, though code example drupal 6. people have provided answers useful both versions of drupal.
i'm working in drupal creating mobile theme drupal 6 website , trying remove unnecessary core , module javascript , css through preprocess_page
function in template.php file. css files removed, can't seem javascript removed. here's i've got. in example, removed except the ajax scripts.
any idea i'm doing wrong?
<?php function mytheme_preprocess_page(&$vars) { //////// remove unneccesary drupal head files mobile version // css $css = drupal_add_css(); // core unset($css['all']['module']['modules/user/user.css']); unset($css['all']['module']['modules/node/node.css']); unset($css['all']['module']['modules/system/defaults.css']); unset($css['all']['module']['modules/system/system.css']); unset($css['all']['module']['modules/system/system-menus.css']); // contributed -- automatically generate path—— easier way $rm[] = drupal_get_path('module','filefield').'/filefield.css'; $rm[] = drupal_get_path('module','flickr').'/flickr.css'; $rm[] = drupal_get_path('module','logintoboggan').'/logintoboggan.css'; $rm[] = drupal_get_path('module','logintoboggan').'/logintoboggan.css'; $rm[] = drupal_get_path('module','fieldgroup').'/fieldgroup.css'; $rm[] = drupal_get_path('module','views').'/css/views.css'; $rm[] = drupal_get_path('module','content').'/theme/content-module.css'; // remove contribs array foreach ($rm $key => $value) { unset($css['all']['module'][$value]); } // javascript $scripts = drupal_add_js(); unset($scripts['module']['sites/all/modules/ajax/ajax.js']); unset($scripts['module']['sites/all/modules/ajax/jquery/jquery.a_form.packed.js']); // recreate tempalate variables $vars['styles'] = drupal_get_css($css); $vars['scripts'] = drupal_get_js('header', $scripts); } ?>
eta: here way scripts print out in header:
<script type="text/javascript" src="/sites/all/modules/ajax/jquery/jquery.a_form.packed.js?p"></script> <script type="text/javascript" src="/sites/all/modules/ajax/ajax.js?p"></script>
i found potentially better solution sort of problem. tried kerri's approach since matt v says worked him, didn't want edit template.php if avoid , regardless wasn't working in environment. problem couple js files throw errors on 1 particular page. did write simple new module runs on desired page. so- created basic .info file , below .module code. worked charm me. replace "mysite_mymodule" whatever name module , replace "my-page-alias" whatever page alias you're trying effect.
<?php /** * implements hook_js_alter(). */ function mysite_mymodule_js_alter(&$javascript) { $alias = drupal_get_path_alias($_get['q']); if ($alias == "my-page-alias") { /** * documentation did , why did it... */ unset($javascript['sites/all/modules/dhtml_menu/dhtml_menu.js']); unset($javascript['sites/all/modules/apachesolr_autocomplete/apachesolr_autocomplete.js']); } }
Comments
Post a Comment