Created
June 25, 2025 10:33
-
-
Save mehrshaddarzi/f502402a961c63b33f21d030390f1d02 to your computer and use it in GitHub Desktop.
Add Default Global font and Color in Eleemntor plugin when new Active Theme
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function set_elementor_global_colors_once() { | |
if ( ! get_option('my_theme_elementor_colors_set') ) { | |
$global_settings = \Elementor\Plugin::$instance->kits_manager->get_active_kit(); | |
$global_settings->set_settings([ | |
'system_colors' => [ | |
'primary-color' => [ | |
'title' => __('Primary Color', 'your-textdomain'), | |
'color' => '#1e73be', | |
], | |
'secondary-color' => [ | |
'title' => __('Secondary Color', 'your-textdomain'), | |
'color' => '#dd3333', | |
], | |
], | |
]); | |
$global_settings->save_settings(); | |
update_option('my_theme_elementor_colors_set', 1); | |
} | |
} | |
add_action('after_switch_theme', 'set_elementor_global_colors_once'); | |
add_action('elementor/controls/controls_registered', function() { | |
// Get the global settings manager | |
$global_settings = \Elementor\Plugin::$instance->kits_manager->get_active_kit(); | |
// Define your custom global colors | |
$global_colors = [ | |
'primary-color' => [ | |
'title' => __('Primary Color', 'your-textdomain'), | |
'color' => '#1e73be', | |
], | |
'secondary-color' => [ | |
'title' => __('Secondary Color', 'your-textdomain'), | |
'color' => '#dd3333', | |
], | |
'accent-color' => [ | |
'title' => __('Accent Color', 'your-textdomain'), | |
'color' => '#81d742', | |
], | |
]; | |
// Set the global colors (overwrites existing ones) | |
$global_settings->set_settings([ | |
'system_colors' => $global_colors, | |
]); | |
// Save the updated settings | |
$global_settings->save_settings(); | |
}); | |
add_action('elementor/controls/controls_registered', function () { | |
$global_settings = \Elementor\Plugin::$instance->kits_manager->get_active_kit(); | |
// تعریف فونتهای دلخواه | |
$global_fonts = [ | |
'primary-font' => [ | |
'title' => __('Primary Font', 'your-textdomain'), | |
'typography_typography' => 'custom', | |
'typography_font_family' => 'IRANSans', | |
'typography_font_weight' => '400', | |
], | |
'secondary-font' => [ | |
'title' => __('Secondary Font', 'your-textdomain'), | |
'typography_typography' => 'custom', | |
'typography_font_family' => 'Vazirmatn', | |
'typography_font_weight' => '600', | |
], | |
]; | |
// تنظیم فونتها | |
$global_settings->set_settings([ | |
'system_typography' => $global_fonts, | |
]); | |
$global_settings->save_settings(); | |
}); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment