Browse Source

fix homepage font (dequeue global styles on front page)

front-page.php is fully self-contained (no wp_head, hand-rolled critical CSS,
zero blocks/presets), but WordPress still injected theme.json's global styles
into its footer. The body + h1-h6 element rules overrode the homepage's inline
typography (serif -> sans, and the card headings jumped to the theme.json type
scale). Dequeue 'global-styles' on is_front_page() only; the rest of the site
keeps theme.json intact.
windhamdavid 4 days ago
parent
commit
0fdc2064bd
1 changed files with 14 additions and 0 deletions
  1. 14 0
      functions.php

+ 14 - 0
functions.php

@@ -188,6 +188,20 @@ function dw_ask_widget() {
 }
 add_action( 'wp_footer', 'dw_ask_widget' );
 
+// front-page.php is fully self-contained (no wp_head, hand-rolled critical CSS, zero
+// blocks/presets), but WordPress still injects theme.json's global styles โ€” and its
+// body/h1-h6 element rules override the homepage's intended typography. Strip them on
+// the front page only; the rest of the site keeps them. (front-page.php skips wp_head,
+// so the global styles print during wp_footer โ€” dequeue before that late-print runs.)
+function dw_no_global_styles_on_home() {
+	if ( is_front_page() ) {
+		wp_dequeue_style( 'global-styles' );
+		wp_dequeue_style( 'global-styles-css-custom-properties' );
+	}
+}
+add_action( 'wp_enqueue_scripts', 'dw_no_global_styles_on_home', 100 );
+add_action( 'wp_footer', 'dw_no_global_styles_on_home', 1 );
+
 // Dev only: on a real content save, ping BrowserSync's reload endpoint so the front-end
 // preview refreshes โ€” DB content changes aren't visible to a filesystem watcher otherwise.
 // Hooks the REST save events the block editor actually fires (+ customizer + nav menus).