Code Monkey home page Code Monkey logo

wp-google-font-picker-control's Introduction

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);
    }
    • title - the title you wish the user to see.
    • location - the query string on the stylesheet for the google font. If the file name for the font is http://fonts.googleapis.com/css?family=Ubuntu+Condensed then the location should be Ubuntu+Condensed.
    • cssDeclaration - the code to be applied to the font-family css property. You can keep is the same as Google suggests or you can set up your own fallbacks.
    • cssClass - the CSS class for the theme cusomizer. You can create any CSS class you want.
  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.

Version

1.1

  • Updated array select box to save font names instead of array indices. See issue #1.

1.0

  • Initial release

wp-google-font-picker-control's People

Contributors

bftrick avatar javadevvictoria avatar

Watchers

James Cloos avatar Benjamin Zekavica avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.