-
-
Save juanfra/2e019f5dadae58e108dbd2b5ea30e917 to your computer and use it in GitHub Desktop.
BBQ typography
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Bossa by NiceThemes. | |
* | |
* This file contains functions to manage the different typography options. | |
* | |
* @see nice_custom_fonts() | |
* @see nice_load_web_fonts() | |
* @see nice_default_fonts() | |
* | |
* @package Bossa | |
* @author NiceThemes <hello@nicethemes.com> | |
* @license GPL-2.0+ | |
* @link http://nicethemes.com/theme/bossa | |
* @copyright 2016 NiceThemes | |
* @since 1.0.0 | |
*/ | |
// If this file is called directly, abort. | |
if ( ! defined( 'WPINC' ) ) { | |
die; | |
} | |
if ( ! function_exists( 'nice_custom_fonts' ) ) : | |
add_action( 'wp_enqueue_scripts', 'nice_custom_fonts', 20 ); | |
/** | |
* Add custom fonts. | |
* | |
* @since 1.0.0 | |
*/ | |
function nice_custom_fonts() { | |
global $nice_options; | |
// Initialize HTML output. | |
$output = ''; | |
wp_enqueue_style( 'nice-options-styles', get_template_directory_uri() . '/includes/assets/css/nice-options.css' ); | |
if ( isset( $nice_options['nice_custom_typography'] ) && ( nice_bool( $nice_options['nice_custom_typography'] ) ) ) { | |
if ( isset( $nice_options['nice_font_body'] ) && $nice_options['nice_font_body'] ) | |
$output .= 'body { ' . nice_custom_font_css( $nice_options['nice_font_body'] ) . ' }' . "\n"; | |
if ( isset( $nice_options['nice_font_nav'] ) && $nice_options['nice_font_nav'] ) | |
$output .= '#navigation .nav li a { ' . nice_custom_font_css( $nice_options['nice_font_nav'] ) . ' }' . "\n"; | |
if ( isset( $nice_options['nice_font_subnav'] ) && $nice_options['nice_font_subnav'] ) | |
$output .= '#top #navigation .nav li ul li a { ' . nice_custom_font_css( $nice_options['nice_font_subnav'] ) . ' }' . "\n"; | |
if ( isset( $nice_options['nice_font_headings'] ) && $nice_options['nice_font_headings'] ) | |
$output .= 'h1, h2, h3, h4, h5, h6, .entry h1, .post .entry h2, .entry h3, .entry h4, .entry h5, .entry h6, #post-author h4 { ' . nice_custom_font_css( $nice_options['nice_font_headings'] ) . ' }' . "\n"; | |
if ( isset( $nice_options['nice_font_buttons'] ) && $nice_options['nice_font_buttons'] ) | |
$output .= 'input[type="submit"], button, #commentform .button, #respond input[type="submit"], .nice-contact-form input[type="submit"] { ' . nice_custom_font_css( $nice_options['nice_font_buttons'] ) . ' }' . "\n"; | |
if ( isset( $nice_options['nice_font_inputs'] ) && $nice_options['nice_font_inputs'] ) | |
$output .= 'input, textarea { ' . nice_custom_font_css( $nice_options['nice_font_inputs'] ) . ' }' . "\n"; | |
if ( isset( $nice_options['nice_font_primary'] ) && $nice_options['nice_font_primary'] ) | |
$output .= '.entry .testimonial blockquote, #tabs ul.niceTabs li a, #tabs .inside li a { ' . nice_custom_font_css( $nice_options['nice_font_primary'] ) . ' }' . "\n"; | |
if ( isset( $nice_options['nice_font_secondary'] ) && $nice_options['nice_font_secondary'] ) | |
$output .= '#footer .testimonials .feedback blockquote, #footer .testimonials .feedback, #tabs .inside li span.meta, #comments .comment-head .date, #comments .comment-head .edit, #comments .comment-head .perma, #comments .reply, #comments .comment-entry p, #post-author { ' . nice_custom_font_css( $nice_options['nice_font_secondary'] ) . ' }' . "\n"; | |
// from now onwards | |
if ( isset( $nice_options['nice_font_post_title'] ) && $nice_options['nice_font_post_title'] ) | |
$output .= '.post h2 { ' . nice_custom_font_css( $nice_options['nice_font_post_title'] ) . ' }' . "\n"; | |
if ( isset( $nice_options['nice_font_post_meta'] ) && $nice_options['nice_font_post_meta'] ) | |
$output .= '.post-meta { ' . nice_custom_font_css( $nice_options['nice_font_post_meta'] ) . ' }' . "\n"; | |
if ( isset( $nice_options['nice_font_post_entry'] ) && $nice_options['nice_font_post_entry'] ) | |
$output .= '.entry, .post-content { ' . nice_custom_font_css( $nice_options['nice_font_post_entry'] ) . ' }' . "\n"; | |
if ( isset( $nice_options['nice_font_infobox_title'] ) && $nice_options['nice_font_infobox_title'] ) | |
$output .= '.infobox .entry-title { ' . nice_custom_font_css( $nice_options['nice_font_infobox_title'] ) . ' }' . "\n"; | |
if ( isset( $nice_options['nice_font_infobox_content'] ) && $nice_options['nice_font_infobox_content'] ) | |
$output .= '.infobox .entry-excerpt, .menu-box li .description, .menu-box p, .menu-card p { ' . nice_custom_font_css( $nice_options['nice_font_infobox_content'] ) . ' }' . "\n"; | |
if ( isset( $nice_options['nice_font_slider_title'] ) && $nice_options['nice_font_slider_title'] ) | |
$output .= '.flexslider .slides li h2 {' . nice_custom_font_css( $nice_options['nice_font_slider_title'] ) . ' }' . "\n"; | |
if ( isset( $nice_options['nice_font_slider_content'] ) && $nice_options['nice_font_slider_content'] ) | |
$output .= '.flex-caption p { ' . nice_custom_font_css( $nice_options['nice_font_slider_content'] ) . ' }' . "\n"; | |
if ( isset( $nice_options['nice_font_widget_titles'] ) && $nice_options['nice_font_widget_titles'] ) | |
$output .= '#sidebar .widget h3 { ' . nice_custom_font_css( $nice_options['nice_font_widget_titles'] ) . ' }' . "\n"; | |
if ( isset( $nice_options['nice_font_footer_widget_titles'] ) && $nice_options['nice_font_footer_widget_titles'] ) | |
$output .= '#footer-widgets h3 { ' . nice_custom_font_css( $nice_options['nice_font_footer_widget_titles'] ) . ' }' . "\n"; | |
if ( isset( $nice_options['nice_font_footer_widget_content'] ) && $nice_options['nice_font_footer_widget_content'] ) | |
$output .= '#footer-widgets .widget { ' . nice_custom_font_css( $nice_options['nice_font_footer_widget_content'] ) . ' }' . "\n"; | |
} | |
// Add Text title and tagline if text title option is enabled | |
if ( isset( $nice_options['nice_texttitle'] ) && ( nice_bool( $nice_options['nice_texttitle'] ) ) ) { | |
if ( $nice_options['nice_font_site_title'] ) { | |
$output .= '#header #top #logo a .text-logo { ' . nice_custom_font_css( $nice_options['nice_font_site_title'] ) . ' }' . "\n"; | |
} | |
} | |
if ( isset( $output ) && $output !== '' ) { | |
$output = strip_tags( '/* Nice Custom Fonts */' . "\n\n" . $output ); | |
wp_add_inline_style( 'nice-options-styles', $output ); | |
} | |
} | |
endif; | |
if ( ! function_exists( 'nice_load_web_fonts' ) ) : | |
add_action( 'wp_head', 'nice_load_web_fonts', 15 ); | |
/** | |
* Load web fonts. | |
* | |
* @since 1.0.0 | |
*/ | |
function nice_load_web_fonts() { | |
global $nice_options; | |
$html = ''; | |
// Go through the options. | |
if ( ( isset( $nice_options['nice_text_title'] ) && ( nice_bool( $nice_options['nice_text_title'] ) ) ) | |
|| ( isset( $nice_options['nice_custom_typography'] ) && ( nice_bool( $nice_options['nice_custom_typography'] ) ) ) | |
) { | |
// Output Google Font CSS in header. | |
if ( $fonts = nice_get_web_fonts_uri() ) { | |
$html .= "\n\n<!-- Nice Google fonts -->\n"; | |
$html .= '<link href="' . $fonts . '" rel="stylesheet" type="text/css" />' . "\n"; | |
$html = str_replace( '|"', '"', $html ); | |
echo $html . "\n\n"; | |
} | |
if ( ( ! nice_bool( $nice_options['nice_custom_typography'] ) ) ) { | |
nice_default_fonts(); | |
} | |
} else { | |
// Fix for updated themes where no typography options were saved. | |
nice_default_fonts(); | |
} | |
} | |
endif; | |
if ( ! function_exists( 'nice_get_default_fonts_uri' ) ) : | |
/** | |
* Obtain URL for default fonts. | |
* | |
* @since 1.0.0 | |
*/ | |
function nice_get_default_fonts_uri() { | |
return apply_filters( 'nice_default_fonts_uri', '//fonts.googleapis.com/css?family=Bree+Serif|Gudea:400,700,400italic' ); | |
} | |
endif; | |
if ( ! function_exists( 'nice_default_fonts' ) ) : | |
/** | |
* HTML to load a default font. | |
* | |
* @since 1.0.0 | |
* @return string | |
*/ | |
function nice_default_fonts() { | |
ob_start(); | |
// Start template. ?> | |
<link href="<?php echo nice_get_default_fonts_uri(); ?>" rel="stylesheet" type="text/css"> | |
<?php // End template. | |
$output = ob_get_contents(); | |
ob_end_clean(); | |
$output = apply_filters( 'nice_default_fonts', $output ); | |
echo $output; | |
} | |
endif; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment