Skip to content

Instantly share code, notes, and snippets.

@norcross
Created April 21, 2017 15:38
Show Gist options
  • Save norcross/216407037d09ad49ae7aefc5e9582cdb to your computer and use it in GitHub Desktop.
Save norcross/216407037d09ad49ae7aefc5e9582cdb to your computer and use it in GitHub Desktop.
add a new font to the Google Fonts array
<?php
add_filter( 'gppro_webfont_stacks', 'dpp_add_nunito_font', 50 );
/**
* Add the Nunito font to the webfont data stack.
*
* @param array $webfonts The existing data array.
*
* @return array $webfonts The modified data array.
*/
function dpp_add_nunito_font( $webfonts ) {
// If the font has already been added, just bail.
if ( array_key_exists( 'nunito', $webfonts ) ) {
return $webfonts;
}
// Set the data for the new font.
$data = array(
'label' => __( 'Nunito', 'gppro-google-webfonts' ),
'css' => '"Nunito", sans-serif',
'src' => 'web',
'val' => 'Nunito:300,400,600,700',
'size' => '',
);
// Add the font to our overall array.
$webfonts = array_merge( $webfonts, array( 'nunito' => $data ) );
// Return the entire array.
return $webfonts;
}
add_filter( 'gppro_webfont_families', 'dpp_add_nunito_family', 50 );
/**
* Add the Nunito font to the webfont family stack.
*
* @param array $fonts The existing data array.
*
* @return array $fonts The modified data array.
*/
function dpp_add_nunito_family( $fonts ) {
// Check to make sure it isn't already in the list.
if ( in_array( 'nunito', $fonts['sans'] ) ) {
return $fonts;
}
// Add the new font into the sans-serif grouping.
$fonts['sans'] = array_merge( $fonts['sans'], array( 'nunito' ) );
// Return the entire array.
return $fonts;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment