Alter the JS paths included in through template.php

13 years ago, October 19, 2011
Reading time: 1 mins

To alter the path of a js file included in .info  in some special cases

like if you want a separate main script file on ur site for some special browsers like iphone or mobiles.

do the following in your template.php

Example: If you want a new js file for ipads 'scripts-ipad.js'

function MYTHEME_js_alter(&$js){
if(is_ipad()) // refer to
        $js['sites/all/themes/MYTHEME/js/scripts.js']['data'] = 'sites/all/themes/MYTHEME/js/scripts-ipad.js';


Where MYTHEME will be your theme name.

You can do similar for CSS files too use MYTHEME_css_alter() explained here

jQuery – How can scroll UP/DOWN be distinguished??
Remove unnecessary css from drupal website
© 2024 Anil Maharjan