Webfonts
apply_filters( 'vikbooking_load_font_assets', ?array $return, VikWPDocument $document, string $font )
Fires during the loading of the default webfont assets.
Description
Plugins can use this filter to prevent the default webfonts loading and/or implement loading of custom font assets.
Particularly useful if you face conflicts with the default webfonts, if your Theme/plugin is already loading webfonts, or if you wish to load your own assets.
Parameters
- $return
-
(?array) The return value container (may be null).
- $document
-
(VikWPDocument) The document object to facilitate registering style-sheet or script files.
- $font
-
(string) The type of font the system is about to load.
This is how the hook will fire. Arguments can be used to apply your own loading technique.
Return value
The callback function should return a value of type bool, indicating whether the framework should keep loading the default webfont assets.
/**
* Register callback to filter "vikbooking_load_font_assets".
* Fires before VikBooking loads webfont assets.
* Use it to prevent the default assets loading and/or to load your own assets.
*
* @param ?array $return The return value container (may be null).
* @param VikWPDocument $document The framework's document object to register assets.
* @param string $font The webfont identifier that is about to be loaded (eg. "fa").
*
* @return bool Whether to proceed loading the default webfont assets.
*/
add_filter('vikbooking_load_font_assets', function($return, $document, $font)
{
// in this example we will load the CSS assets for an older FontAwesome version (5.12.1)
// such FA version used to be the default webfont library until VikBooking v1.8.7
// you can use absolute internal or external URLs, as well as relative (internal) URLs
// load the main FontAwesome CSS file from the remote CDN
$document->addStyleSheet('https://use.fontawesome.com/releases/v5.12.1/css/fontawesome.css');
// load additional CSS files from the remote CDN, needed to support specific FA webfont styles
$document->addStyleSheet('https://use.fontawesome.com/releases/v5.12.1/css/solid.css');
$document->addStyleSheet('https://use.fontawesome.com/releases/v5.12.1/css/regular.css');
// tell the system not to load the default webfont assets
return false;
}, 10, 3); This is the main hook that gets fired whenever VikBooking runs and requires Webfonts to be loaded. Use it to resolve conflicts, duplicate assets being loaded, or to load your preferred Webfont type or version.
There is also another (minor) hook that runs for loading additional Webfont assets required by VikBooking. Webfonts usually come with different styles and VikBooking (or Vik Channel Manager) may need to load additional assets.
/**
* Register callback to filter "vikbooking_load_font_asset_style".
* Fires before VikBooking loads a specific webfont style asset.
* Use it to prevent the default assets loading and/or to load your own assets.
*
* @param ?array $return The return value container (may be null).
* @param VikWPDocument $document The framework's document object to register assets.
* @param string $style The webfont style type that is about to be loaded (eg. "brands").
*
* @return bool Whether to proceed loading the default webfont style asset.
*/
add_filter('vikbooking_load_font_asset_style', function($return, $document, $style)
{
// in this example we will load the CSS style asset "brands" for an older FontAwesome version (5.12.1)
// such FA version used to be the default webfont library until VikBooking v1.8.7
// you can use absolute internal or external URLs, as well as relative (internal) URLs
// load the FontAwesome CSS file for "brands" icons
$document->addStyleSheet('https://use.fontawesome.com/releases/v5.12.1/css/brands.css');
// tell the system not to load the default webfont style asset
return false;
}, 10, 3);