Browsing "Mobile"
Mar 22, 2012 - Mobile, WordPress    Comments Off on Responsive design: adding scripts and styles

Responsive design: adding scripts and styles

add_action('wp_print_scripts', 'themename_add_scripts');
 
function themename_add_scripts() {
	if(!is_admin()){
    	wp_enqueue_script('theme_jquery', get_bloginfo('template_url').'/js/theme-jquery.js', array('jquery'),NULL,TRUE); 
    	if(is_front_page()){
    		wp_enqueue_script('homepage_jquery', get_bloginfo('template_url').'/js/homepage-jquery.js', array('jquery'),NULL,TRUE);    
    	}
       	if(is_mobile()){
       		//change some content with jQuery
       		wp_enqueue_script('mobile_jquery', get_bloginfo('template_url').'/js/mobile-jquery.js', array('jquery'),NULL,TRUE); 
       		//add support for older iphones
			$agent = $_SERVER['HTTP_USER_AGENT'];
			$version = preg_match('/OS\s([\d+_?]*)\slike/i', $agent, $matches);
			$version = str_replace('_', '.', $matches[1]);
			if (!(preg_match('/ip(hone|ad|od)/i', $agent)) || ((preg_match('/ip(hone|ad|od)/i', $agent) && $version < 5))) {
				wp_enqueue_script('ios4_jquery', get_bloginfo('template_url').'/js/ios4-jquery.js', array('jquery'),NULL,TRUE); 
			}
       	}
	}
}
add_action('wp_print_styles', 'themename_add_styles');
 
function themename_add_styles() {
    if(!is_admin()){
        wp_enqueue_style('desktop', get_stylesheet_directory_uri().'/css/960.css', NULL, NULL, 'screen and (min-width: 769px)');   
        wp_enqueue_style('ipad', get_stylesheet_directory_uri().'/css/ipad.css', NULL, NULL, 'only screen and (min-device-width : 768px) and (max-device-width : 1024px)');           
        wp_enqueue_style('mobile', get_stylesheet_directory_uri().'/css/mobile.css', NULL, NULL, 'only screen and (max-width: 768px)');     
    }
}