Hey @aristath,
I've decided to create a separate post for this.
// Kirki Custom Default Fonts
function my_function( $standard_fonts ) {
$standard_fonts['helvetica_neue'] = array(
'label' => 'Helvetica Neue',
'variants' => array( 'regular', 'italic', '700', '700italic' ),
'stack' => '"Helvetica Neue", Helvetica, Arial, sans-serif',
);
$standard_fonts['helvetica'] = array(
'label' => 'Helvetica',
'variants' => array( 'regular', 'italic', '700', '700italic' ),
'stack' => 'Helvetica, Arial, sans-serif',
);
$standard_fonts['arial'] = array(
'label' => 'Arial',
'variants' => array( 'regular', 'italic', '700', '700italic' ),
'stack' => 'Arial, Helvetica, sans-serif',
);
return $standard_fonts;
}
add_filter( 'kirki/fonts/standard_fonts', 'my_function', 0 );
The issue with this implementation is, that the variants are being ignored. No matter what I add, I always get regular, italic, 700 and 700 italic.
Note: Extending the defaults optgroup with custom fonts was quite easy using this method. I used to let the users of my theme add their own custom fonts that way.
function default_choices(){
return array(
'fonts' => apply_filters( 'kirki_font_choices', array() )
);
}
that I use in the typography field like this:
'choices' => default_font_choices()
That basically allows me to do something like this to change or even disable the google fonts optgroup for instance:
function custom_google_fonts( $custom_choice = array() ) {
$choices = array(
'google' => array( 'popularity', 4 ),
);
$custom_choice = array_merge( $choices, $custom_choice );
return $custom_choice;
}
add_filter( 'kirki_font_choices', 'custom_google_fonts', 20 );
Here's how I use the filter to add a custom optgroup for the "Custom Fonts":
function custom_font_group( $custom_choice = array() ) {
$choices = array(
'families' => array(
'custom' => array(
'text' => esc_attr__( 'Custom Fonts', 'textdomain' ),
'children' => array(
array( 'id' => 'ABC', 'text' => 'ABC' ),
),
),
),
'variants' => array(
'ABC' => array( '200', '300', '400','400italic', '500','500italic', '600','600italic', '700','700italic', '800','800italic', 'regular','italic' ),
),
);
$custom_choice = array_merge_recursive( $choices, $custom_choice );
return $custom_choice;
}
// add_filter( 'kirki_font_choices', 'custom_font_group', 20 );
This leads me to the following questions:
What I could do is, create another filter (looking exactly the same) and use array_merge_recursive() to add - let's say the typekit fonts - to the same optgroup. That creates other problems though.
So now, am I missing something? :D
The deprecated filter was quite nice and easy to understand for users. Check this post from our docs where I was using this filter to let people add their own custom fonts to the typography dropdown.
I'd love to hear your thoughts!
Keep up the great work! :)
3.0.31
Hi @aristath,
would love to hear your thoughts on this.
Best,
David
I'm sorry for the long delay here.... Time is a bit limited and I haven't had a chance to look into this yet. I'll try to go through all tickets this weekend.
Filterable default choices:
function default_choices(){
return array(
'fonts' => apply_filters( 'kirki_font_choices', array() )
);
}
Called like this inside the typography setting:
'choices' => default_font_choices()
Using the filter to add a custom optgroup to the typography dropdown (you can use multiple functions similar to this one to create multiple custom optgroups):
// Custom Font Group
function my_custom_optgroup( $custom_choice ) {
$custom_choice['families']['custom_fonts'] = array(
'text' => esc_attr__( 'Custom Fonts', 'textdomain' ),
'children' => array(
array( 'id' => 'ProximaNova', 'text' => 'Proxima Nova' ),
),
);
$custom_choice['variants'] = array(
'ProximaNova' => array( '200', '300', '400', '400italic', '500', '500italic', '600', '600italic', '700', '700italic', '800', '800italic', 'regular', 'italic' ),
);
return $custom_choice;
}
add_filter( 'kirki_font_choices', 'my_custom_optgroup', 20 );
Hello!
Is it working for you now?
Hi @vlthemes,
check out this post I've put together – https://mapsteps.com/blog/add-custom-optgroups-to-kirki-typography-dropdown/
It`s not working now.
are you running 3.0.36? Haven't tested this with the current version.
Yeah. It is sad. I don't know why it is not working.
But this is working:
https://take.ms/Kl0Ta
@aristath Hello!
Thank you for reopen this ticket.
Hope this problem will be fixed ASAP.
Nevermind, I did it.
If you can help me to improve this (add cache, typekit support, etc) you are welcome.
Hope this problem will be fixed ASAP.
To be honest I don't understand what the problem is, could you elaborate?
If you need to post code examples please post actual code and not screenshots. I can't copy-paste screenshots to test things. :+1:
I'm 100% not sure what the problem was.
1) I received a letter from client that his fonts stopped working. (I use my own implementation for custom fonts)
2) Updated Kirki to the recent version. Not working.
3) Try to use this code from @MapSteps But still not working.
4) Deactivate all not recommnded plugins. (exceptt included plugins in the theme)
5) It works.
I have already think that the problem is in the new update of the Kirki, but … no.
Thank you for your quick feedback. Close this ticket.
Best regards.
Most helpful comment
I'm 100% not sure what the problem was.
1) I received a letter from client that his fonts stopped working. (I use my own implementation for custom fonts)
2) Updated Kirki to the recent version. Not working.
3) Try to use this code from @MapSteps But still not working.
4) Deactivate all not recommnded plugins. (exceptt included plugins in the theme)
5) It works.
I have already think that the problem is in the new update of the Kirki, but … no.
Thank you for your quick feedback. Close this ticket.
Best regards.