Comments (11)
This works although I'm not sure about the logic. I just quickly did it since I need it for a child theme since some use weight of 600.
get_font()
could potentially in some weird way return null or not pass sanitization but getting the font weight will already have run at that point.
from primer.
Yeah I almost implemented this but decided against it since I wasn't sure if there was a use case, sounds like there is!
This approach won't really work because weights need to be tied to individual fonts. I'll think of a way to implement this.
from primer.
Well, I thought about doing it to the individual fonts too but it was going to increase the complexity a lot. You'd probably have to do some function like primer_font_weights and you define each weight for each use of the font with a fallback if not defined. That could be a lot to manage... Haha
My solution just assumes the font-weight is defined in the sass and never needs to change. E.g. if you have a medium font weight you have that regardless of what font you use.
from primer.
But I do agree on a individual font basis, would be better
from primer.
@schrapel Please test this out. This will allow a Child theme to specify weights on a per-font basis.
Rough example:
add_filter( 'primer_font_weights', function( $weights, $font ) {
return ( 'Open Sans' === $font ) ? [ 300, 600 ] : $weights;
}, 10, 2 );
from primer.
I just found a flaw in the way fonts are loaded...working on a fix now
from primer.
@schrapel Alright I think this is getting better now. Fonts were being duplicated when used in multiple types. So if you were using Open Sans for all 3 areas, it would appear 3 times in the Google Font URL call!
Also I decided to pass the $font_type
to the filter as well. This way a Child theme can decide "I want 700 weight to be available for all Headers" or "Use a 700 weight for Open Sans when used as a Header". And everything will get normalized, and duplicates will be removed, before the final Google Font URL is built. I think this is pretty flexible now.
add_filter( 'primer_font_weights', function( $weights, $font ) {
return ( 'Open Sans' === $font ) ? [ 300, 600 ] : $weights;
}, 10, 2 );
add_filter( 'primer_font_weights', function( $weights, $font, $font_type ) {
return ( 'header_font' === $font_type ) ? [ 400, 600, 700 ] : $weights;
}, 10, 3 );
add_filter( 'primer_font_weights', function( $weights, $font, $font_type ) {
return ( 'Open Sans' === $font && 'header_font' === $font_type ) ? [ 400, 600, 700 ] : $weights;
}, 10, 3 );
from primer.
Merged into develop in ee5cb50
from primer.
Awesome, but now if you specify a font weight in this way. You also have to specify the css somehow too?
from primer.
That CSS will just have to be in the child theme and this filter just adds whatever weights the child says it needs. You're right that this doesn't give total control, and maybe we should switch the order of the args in the filter since $font
will only be used in rare situations - or by folks overriding their child theme.
Can we move forward with what we have now and think about a more complete font weights API after 1.0?
from primer.
from primer.
Related Issues (20)
- Update php version with php 7+ HOT 2
- Fix Susy 3.0+ mixin errors
- ISBAT see the editor width change based on the selected page layout HOT 3
- ISBAT experience the CoBlocks form block as styled on the front-end HOT 1
- Primer theme update to 1.8.7 breaks Blubrry plugin on PHP version 7.x when trying to upload media. Popup displays WordPress 500 ISE. HOT 1
- Uninstall button missing HOT 1
- Add support for the wp_body_open hook HOT 1
- Post area 100% height HOT 1
- Not compatible with latest wordpress version HOT 3
- Javascript error during page edit after upgrading from WordPress 5.2.4 to 5.3 HOT 1
- WooCommerce theme overrides featured-image header setting HOT 2
- Primer wp theme problem
- Sidebar doesn't scroll HOT 1
- On WordPress 5.5 and Gutenberg editor, the background color in editor is no longer inherited(works fine in WP 5.4.2) HOT 1
- Video in header not showing on mobile - Uptown Style HOT 4
- Images and text in Gutenberg have differences in sizing compaired to the default theme. HOT 1
- Choose whether to display Secondary Sidebar Widget on mobile devices HOT 1
- Adding a preload feature for randomized header image HOT 1
- Add support for non-Google fonts HOT 2
- Videos not working on mobile and also Safari HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from primer.