From 0c8e14a3ad9d67495fb4ea3161cbe0c77dfee42a 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 --- wp-content/themes/twentytwelve/functions.php | 10 ++++++++++ wp-content/themes/twentytwelve/style.css | 5 ++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/wp-content/themes/twentytwelve/functions.php b/wp-content/themes/twentytwelve/functions.php index 649f47823b..d516090f69 100644 --- a/wp-content/themes/twentytwelve/functions.php +++ b/wp-content/themes/twentytwelve/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/wp-content/themes/twentytwelve/style.css b/wp-content/themes/twentytwelve/style.css index 8130e5e424..ecaf52075f 100644 --- a/wp-content/themes/twentytwelve/style.css +++ b/wp-content/themes/twentytwelve/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;