mirror of
https://github.com/WordPress/WordPress.git
synced 2024-12-23 09:37:42 +01:00
Twenty Twelve: load our special Google Font in the visual editor to improve user experience. Props to the Konstanthemes: kovshenin and obenland.
Closes #22499. See also r23672. git-svn-id: http://core.svn.wordpress.org/trunk@23713 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
63dfa74c9f
commit
8415217e90
@ -82,6 +82,46 @@ add_action( 'after_setup_theme', 'twentytwelve_setup' );
|
||||
*/
|
||||
require( get_template_directory() . '/inc/custom-header.php' );
|
||||
|
||||
/**
|
||||
* Returns the Google font stylesheet URL if available.
|
||||
*
|
||||
* The use of Open Sans by default is localized. For languages that use
|
||||
* characters not supported by the font, the font can be disabled.
|
||||
*
|
||||
* @since Twenty Twelve 1.2
|
||||
*
|
||||
* @return string Font stylesheet or empty string if disabled.
|
||||
*/
|
||||
function twentytwelve_get_font_url() {
|
||||
$font_url = '';
|
||||
|
||||
/* translators: If there are characters in your language that are not supported
|
||||
by Open Sans, translate this to 'off'. Do not translate into your own language. */
|
||||
if ( 'off' !== _x( 'on', 'Open Sans font: on or off', 'twentytwelve' ) ) {
|
||||
$subsets = 'latin,latin-ext';
|
||||
|
||||
/* translators: To add an additional Open Sans character subset specific to your language, translate
|
||||
this to 'greek', 'cyrillic' or 'vietnamese'. Do not translate into your own language. */
|
||||
$subset = _x( 'no-subset', 'Open Sans font: add new subset (greek, cyrillic, vietnamese)', 'twentytwelve' );
|
||||
|
||||
if ( 'cyrillic' == $subset )
|
||||
$subsets .= ',cyrillic,cyrillic-ext';
|
||||
elseif ( 'greek' == $subset )
|
||||
$subsets .= ',greek,greek-ext';
|
||||
elseif ( 'vietnamese' == $subset )
|
||||
$subsets .= ',vietnamese';
|
||||
|
||||
$protocol = is_ssl() ? 'https' : 'http';
|
||||
$query_args = array(
|
||||
'family' => 'Open+Sans:400italic,700italic,400,700',
|
||||
'subset' => $subsets,
|
||||
);
|
||||
$font_url = add_query_arg( $query_args, "$protocol://fonts.googleapis.com/css" );
|
||||
}
|
||||
|
||||
return $font_url;
|
||||
}
|
||||
|
||||
/**
|
||||
* Enqueues scripts and styles for front-end.
|
||||
*
|
||||
@ -102,42 +142,9 @@ function twentytwelve_scripts_styles() {
|
||||
*/
|
||||
wp_enqueue_script( 'twentytwelve-navigation', get_template_directory_uri() . '/js/navigation.js', array(), '1.0', true );
|
||||
|
||||
/*
|
||||
* Loads our special font CSS file.
|
||||
*
|
||||
* The use of Open Sans by default is localized. For languages that use
|
||||
* characters not supported by the font, the font can be disabled.
|
||||
*
|
||||
* 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 );
|
||||
*/
|
||||
|
||||
/* translators: If there are characters in your language that are not supported
|
||||
by Open Sans, translate this to 'off'. Do not translate into your own language. */
|
||||
if ( 'off' !== _x( 'on', 'Open Sans font: on or off', 'twentytwelve' ) ) {
|
||||
$subsets = 'latin,latin-ext';
|
||||
|
||||
/* translators: To add an additional Open Sans character subset specific to your language, translate
|
||||
this to 'greek', 'cyrillic' or 'vietnamese'. Do not translate into your own language. */
|
||||
$subset = _x( 'no-subset', 'Open Sans font: add new subset (greek, cyrillic, vietnamese)', 'twentytwelve' );
|
||||
|
||||
if ( 'cyrillic' == $subset )
|
||||
$subsets .= ',cyrillic,cyrillic-ext';
|
||||
elseif ( 'greek' == $subset )
|
||||
$subsets .= ',greek,greek-ext';
|
||||
elseif ( 'vietnamese' == $subset )
|
||||
$subsets .= ',vietnamese';
|
||||
|
||||
$protocol = is_ssl() ? 'https' : 'http';
|
||||
$query_args = array(
|
||||
'family' => 'Open+Sans:400italic,700italic,400,700',
|
||||
'subset' => $subsets,
|
||||
);
|
||||
wp_enqueue_style( 'twentytwelve-fonts', add_query_arg( $query_args, "$protocol://fonts.googleapis.com/css" ), array(), null );
|
||||
}
|
||||
$font_url = twentytwelve_get_font_url();
|
||||
if ( ! empty( $font_url ) )
|
||||
wp_enqueue_style( 'twentytwelve-fonts', esc_url_raw( $font_url ), array(), null );
|
||||
|
||||
/*
|
||||
* Loads our main stylesheet.
|
||||
@ -152,6 +159,31 @@ function twentytwelve_scripts_styles() {
|
||||
}
|
||||
add_action( 'wp_enqueue_scripts', 'twentytwelve_scripts_styles' );
|
||||
|
||||
/**
|
||||
* Adds additional stylesheets to the TinyMCE editor if needed.
|
||||
*
|
||||
* @uses twentytwelve_get_font_url() To get the Google Font stylesheet URL.
|
||||
*
|
||||
* @since Twenty Twelve 1.2
|
||||
*
|
||||
* @param string $mce_css CSS path to load in TinyMCE.
|
||||
* @return string
|
||||
*/
|
||||
function twentytwelve_mce_css( $mce_css ) {
|
||||
$font_url = twentytwelve_get_font_url();
|
||||
|
||||
if ( empty( $font_url ) )
|
||||
return $mce_css;
|
||||
|
||||
if ( ! empty( $mce_css ) )
|
||||
$mce_css .= ',';
|
||||
|
||||
$mce_css .= esc_url_raw( str_replace( ',', '%2C', $font_url ) );
|
||||
|
||||
return $mce_css;
|
||||
}
|
||||
add_filter( 'mce_css', 'twentytwelve_mce_css' );
|
||||
|
||||
/**
|
||||
* Creates a nicely formatted and more specific title element text
|
||||
* for output in head of document, based on current view.
|
||||
|
Loading…
Reference in New Issue
Block a user