Plugin / ACF: Google Font Selector

Daniel Pataki

Description

Description

This plugin allows you to create a Google font selector field with different options. The plugin also creates the font request in the theme header to autoload the fonts if you’d like. Font variants and charsets can be selected separately to make font loading more flexible and optimized.

Font options added to any options page will always be enqueued. Any fonts added to post pages will only be enqueued when that specific post is displayed.

Google API Key

To grab the font list from Google you’ll need an API key. This is free and easy to do, take a look at this guide to get an API key.

ACF Compatibility

This ACF field type is compatible with both ACF 4 and ACF 5.

Thanks

Usage

Once installed the list of Google Fonts will be retrieved from a static file included in the plugin. If you would like the list to be pulled from the Google API you will need to define your API key. You can do this in Settings->Google Font Selector in the admin.

For Developers

There are a few more advanced controls you can set to make the plugin do your bidding. If you would like to hard-code the API key and disable users from seeing the nag screen and setting panel you can define the ACFGFS_API_KEY constant.

define( 'ACFGFS_API_KEY', 'your_google_api_key' );

The ACFGFS_REFRESH constant can controls how frequently the plugin checks the Google API for updates. The value is in seconds, 86400 would be a day. The default is set to 7 days.

define( 'ACFGFS_REFRESH', 259200 );

If you would like to disable the automatic enqueueing of fonts you can use the ACFGFS_NOENQUEUE constant. The fonts are only enqueued automatically when this constant is not defined. Define the constant to disable enqueueing.

define( 'ACFGFS_NOENQUEUE', true );

If you want to modify the fonts that are loaded on a page you can use the acfgfs/enqueued_fonts filter. This should return an array of fonts with variants and subsets needed, something like this:

array(
    'font' => 'Open Sans',
    'variants' => array( 'regular', '700' ),
    'subsets' => array( 'latin' )
)

New in 3.0.1 is the ability to control the fonts displayed in the dropdown. If you only want to give your users access to a smaller portion of Google fonts you can use the acfgfs/font_dropdown_array filter to modify the array that is used to generate the dropdown. Please return an array where the key and the value are both the names of the font.

add_filter( 'acfgfs/font_dropdown_array', 'my_font_list' );
function my_font_list( $fonts ) {
    $fonts = array(
        'Raleway' => 'Raleway',
        'Lato' => 'Lato'
    );
    return $fonts;
}

DIRECTORY DISCLAIMER

The information provided in this THEME/PLUGIN DIRECTORY is made available for information purposes only, and intended to serve as a resource to enable visitors to select a relevant theme or plugin. wpSocket gives no warranty of any kind, express or implied with regard to the information, including without limitation any warranty that the particular theme or plugin that you select is qualified on your situation.

The information in the individual theme or plugin displayed in the Directory is provided by the owners and contributors themselves. wpSocket gives no warranty as to the accuracy of the information and will not be liable to you for any loss or damage suffered by you as a consequence of your reliance on the information.

Links to respective sites are offered to assist in accessing additional information. The links may be outdated or broken. Connect to outside sites at your own risk. The Theme/Plugin Directory does not endorse the content or accuracy of any listing or external website.

While information is made available, no guarantee is given that the details provided are correct, complete or up-to-date.

wpSocket is not related to the theme or plugin, and also not responsible and expressly disclaims all liability for, damages of any kind, arising out of the use, reference to, or reliance on, any information or business listed throughout our site.

Keep Leading Your Followers!
Share it for them.