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. 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 enqueues. Any fonts added to post pages will only be enqueued when that specific post is displayed.
This ACF field type is compatible with ACF 4 and ACF 5.
Installation
- Copy the
acf-google_font_selector
folder into your wp-content/plugins
folder
- Activate the Google Font Selector plugin via the plugins admin page
- Create a new field via ACF and select the Google Font Selector type
- Please refer to the description for more info regarding the field type settings
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 the theme's function file for example.
define( 'ACFGFS_API_KEY', 'your_google_api_key' );
It's super easy to get an API key, just head on over to the
Google API Console, create a new project and get a browser api key.
The
ACFGFS_REFRESH
constant can also be defined, it 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 3 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 );