1 |
$imageURL = image_style_url('YOUR_STYLE_NAME', $content['field_image']['#items'][0]['uri']); |
1 |
$imageURL = image_style_url('YOUR_STYLE_NAME', $content['field_image']['#items'][0]['uri']); |
Add this simple function into your theme’s template.php in order to strip out unnecessary whitespace and line breaks, saving a bit of file size where possible (I saved 17kb from my homepage). If a page contains a <pre> or <textarea> tag, it is left alone, as to not affect code blocks or text typed in a form.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
// Minify HTML output. function sonspring_process_html(&$vars) { $before = array( "/>\s\s+/", "/\s\s+</", "/>\t+</", "/\s\s+(?=\w)/", "/(?<=\w)\s\s+/" ); $after = array('> ', ' <', '> <', ' ', ' '); // Page top. $page_top = $vars['page_top']; $page_top = preg_replace($before, $after, $page_top); $vars['page_top'] = $page_top; // Page content. if (!preg_match('/<pre|<textarea/', $vars['page'])) { $page = $vars['page']; $page = preg_replace($before, $after, $page); $vars['page'] = $page; } // Page bottom. $page_bottom = $vars['page_bottom']; $page_bottom = preg_replace($before, $after, $page_bottom); $vars['page_bottom'] = $page_bottom . drupal_get_js('footer'); } |
In your template.php, you can exclude Drupal’s system CSS files, or any CSS file that wasnt added by your theme (this includes CSS added by modules) using this PHP snippet:
1 2 3 4 5 6 7 8 9 10 |
function YOURTHEME_css_alter(&$css) { if (!user_is_logged_in()) { foreach ($css as $key => $value) { if ($value['group'] != CSS_THEME) { $exclude[$key] = FALSE; } } $css = array_diff_key($css, $exclude); } } |
So you want to have a base.css file on all pages, then a homepage.css file just for the homepage, and non-homepage.css for all other pages? Here’s how:
In your themes’ .info file, include the base.css file:
1 |
stylesheets[all][] = css/base.css |
In your themes’ template.php file:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
function YOURTHEME_preprocess_page(&$vars) { // // home/non-home specific css // $homepage_css_options = array( 'type' => 'inline', 'scope' => 'header', 'group' => CSS_THEME, 'weight' => 9999, 'preprocess' => FALSE, ); $nothomepage_css_options = array( 'type' => 'file', 'scope' => 'header', 'group' => CSS_THEME, 'weight' => 9999, 'preprocess' => TRUE, ); if ($vars['is_front'] == TRUE) { //inline the homepage css, minified by Gulp drupal_add_css(file_get_contents(drupal_get_path('theme', 'YOURTHEME') . '/css/homepage.min.css'), $homepage_css_options); } else { //inline css file for all pages except homepage drupal_add_css(drupal_get_path('theme', 'YOURTHEME') . '/css/not-homepage.css', $nothomepage_css_options); } } |
Note: In the code above I have chosen to inline the homepage only CSS.
Tip me some bitcoin: