From 5f5461842720b7e42cd4518991d6913ea557dd5d Mon Sep 17 00:00:00 2001 From: Lance Willett Date: Thu, 30 Aug 2012 16:59:22 +0000 Subject: [PATCH] Twenty Twelve: move Open Sans custom font loading to a body class to allow easier overriding, fixes #21694. * Use wp_style_is() to check for the enqueued CSS file before adding the body class value. * Add a sample dequeue method in the comments as documentation for child themers and their ilk. Props viniciusmassuchetto, nacin, and obenland. git-svn-id: http://core.svn.wordpress.org/trunk@21668 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- functions.php | 10 ++++++++++ style.css | 5 ++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/functions.php b/functions.php index 649f47823..d516090f6 100644 --- a/functions.php +++ b/functions.php @@ -102,6 +102,12 @@ function twentytwelve_scripts_styles() { /* * Loads our special font CSS file. + * + * To disable in a child theme, use wp_dequeue_style() + * function mytheme_dequeue_fonts() { + * wp_dequeue_style( 'twentytwelve-fonts' ); + * } + * add_action( 'wp_enqueue_scripts', 'mytheme_dequeue_fonts', 11 ); */ $protocol = is_ssl() ? 'https' : 'http'; wp_enqueue_style( 'twentytwelve-fonts', "$protocol://fonts.googleapis.com/css?family=Open+Sans:400italic,700italic,400,700", array(), null ); @@ -376,6 +382,10 @@ function twentytwelve_body_class( $classes ) { elseif ( in_array( $background_color, array( 'fff', 'ffffff' ) ) ) $classes[] = 'custom-background-white'; + // Enable custom font class only if the font CSS is queued to load. + if ( wp_style_is( 'twentytwelve-fonts', 'queue' ) ) + $classes[] = 'custom-font-enabled'; + return $classes; } add_filter( 'body_class', 'twentytwelve_body_class' ); diff --git a/style.css b/style.css index 8130e5e42..ecaf52075 100644 --- a/style.css +++ b/style.css @@ -437,10 +437,13 @@ html { body { font-size: 14px; font-size: 1rem; - font-family: "Open Sans", Helvetica, Arial, sans-serif; + font-family: Helvetica, Arial, sans-serif; text-rendering: optimizeLegibility; color: #444; } +body.custom-font-enabled { + font-family: "Open Sans", Helvetica, Arial, sans-serif; +} a { outline: none; color: #21759b;