Alter the JS paths included in theme.info 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 http://anilmaharjan.com.np/index.php/blog/2011/10/to-detect-an-ipad-or-an-iphone-in-php-http_user_agent
        $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 http://anilmaharjan.com.np/index.php/blog/2011/10/remove-unnecessary-css-from-drupal-website

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