Problem:

The Salient theme for WordPress uses WPBakery Page Builder to design pages. Within this plugin, you have the option to add elements. One of these elements is the custom heading element. This offers many formatting options for headings.
However, the list of Google Fonts is not the complete list as found on the Google Fonts website. The WPBakery Page Builder code contains a fixed list of not all the fonts from which you can choose.
Fortunately, WPBakery Page Builder offers an add_filter() option to expand the list of Google Fonts for the custom heading element. I received a request to add the missing Google Font Barlow.
Solution:
The solution is very easy. Add the snippet below to a plugin or the functions.php file of your child theme:
function salient_child_add_google_fonts(array $fonts) : array {
$fonts[] = (object) [
'font_family' => 'Barlow',
'font_styles' => 'regular,700,800',
'font_types' => '400 regular:400:normal,700 bold regular:700:normal,800 bold regular:800:normal'
];
usort($fonts, function($a, $b) {
return strcasecmp($a->font_family, $b->font_family);
});
return $fonts;
}
add_filter('vc_google_fonts_get_fonts_filter','salient_child_add_google_fonts');
> Read more blogs about WordPress
Explanation of code:
- The first 5 rules of the function will add the Barlow font to the existing array of fonts supplied via the $fonts parameter
- You can duplicate this code if you need to add some extra Google Fonts that are not already in the list
- Because the Barlow font is added at the end of the array I sort the complete array based on the ‘font_family’ parameter
Tested on:
WordPress 6.8.3 with Salient thema 17.4.1 and WP Bakery Page Builder 8.4.2
