Skip to content

JaydenGui/tyful

 
 

Repository files navigation

Google Font Picker Control

Description

This WordPress plugin creates a new control type for the WordPress Theme Customizer. It will allow you to easily create a fancy looking Google Web Font picker.

Usage

  1. Include & activate the plugin

  2. Pick out your favorite Google Web Fonts

  3. Open your functions.php file

  4. Save your favorite fonts in an array like so:

    $customFontFamilies;
    if (class_exists('Google_Font_Collection'))
    {
    	$fonts[] = array(
    		"title" => "Ubuntu Condensed", 
    		"location" => "Ubuntu+Condensed", 
    		"cssDeclaration" => "'Ubuntu Condensed', sans-serif", 
    		"cssClass" => "ubuntuCondensed"
    	);
    	$customFontFamilies = new Google_Font_Collection($fonts);
    }
  5. Create the control

    if (class_exists('Google_Font_Picker_Custom_Control'))
    { 
    	// make sure we have the control included
    	$wp_customize->add_control( new Google_Font_Picker_Custom_Control( $wp_customize, 'font_family_control', array(
    		'label'				=> __( 'Font Family', 'mytheme' ),
    		'section'			=> 'mytheme_new_section_fonts',
    		'settings'			=> 'font_family',
    		'choices' 			=> $customFontFamilies->getFontFamilyNameArray(),
    		'fonts'				=> $customFontFamilies
    	)));
    }

Results

screenshot

FAQ

  1. Can I only add one font to the $fonts array in step 4?

    No, you can add as many as you like. IMO eight choices looks pretty and gives the user tons of options.

  2. What's up with the class_exists() functions?

    Those are there so that if you were to ever deactivate or uninstall the plugin that your site wouldn't crash. If you do uninstall the plugin the control will simply not load. There shouldn't be any errors.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Java 71.5%
  • ActionScript 9.9%
  • C++ 6.0%
  • JavaScript 4.5%
  • Other 3.3%
  • HTML 1.5%
  • Other 3.3%