Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save kamalahmed/145a118cc4b64a9be5a08c25c12c5e18 to your computer and use it in GitHub Desktop.
Save kamalahmed/145a118cc4b64a9be5a08c25c12c5e18 to your computer and use it in GitHub Desktop.
Update or Set new default fonts in Elementor from your plugin or theme
<?php
add_action('elementor/loaded', 'prefix_register_custom_default_fonts');
// register custom fonts only when elementor is ready
function prefix_register_custom_default_fonts(){
$new_default_fonts = [
//Primary Headline
[
'font_family' => 'Playfair Display',
'font_weight' => 400
],
//Secondary Headline
[
'font_family' => 'Lora',
'font_weight' => 400
],
//Body Text
[
'font_family' => 'Nunito Sans',
'font_weight' => 400
],
//Accent Text
[
'font_family' => 'Nunito Sans',
'font_weight' => 400
],
];
$typography = new \Elementor\Scheme_Typography();
$typography->save_scheme( $new_default_fonts);
/*
get saved fonts in anywhere in your theme/plugin. You will receive an array of 4 fonts.
$updated_fonts = $typography->get_scheme_value();
NOTE: You may want to use an option to track update of this method, because you need to make sure you update the default fonts once,
Otherwise, when a user change the fonts from elementor editor, it will be overridden by your function. I prefer to follow a style like below.
if (!get_option( 'prefix_updated_elementor_fonts')){
$typography = new Scheme_Typography();
$typography->save_scheme( $xlaw_default_fonts);
update_option( 'prefix_updated_elementor_fonts', 1);
}
*/
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment