Skip to content

Filter Google fonts weights or make a public method for getting Google fonts #7622

@hogash

Description

@hogash

Prerequisites

  • I have searched for similar features requests in both open and closed tickets and cannot find a duplicate.
  • The feature is still missing in the latest stable version of Elementor ( Elementor Pro. )

What problem is your feature request going to solve? Please describe.
Minimize Google fonts's request by decreasing the font weights/variants list. Currently it loads everything, which does cover 99% of use cases, however it's a general forced (and most likely temporary) solution.

It's really frustrating to load all these variants (maybe hundred of kb), when i'm only using regular and bold.

Describe the solution you'd like
Would like to filter the font weight list eg: https://github.com/elementor/elementor/blob/master/includes/frontend.php#L651 . eg:

foreach ( $google_fonts['google'] as &$font ) {
	$font_weights = apply_filters('elementor/frontend/google_fonts_weights', '100,100italic,200,200italic,300,300italic,400,400italic,500,500italic,600,600italic,700,700italic,800,800italic,900,900italic', $font, $google_fonts_index);
	$font = str_replace( ' ', '+', $font ) . ':' . $font_weights;
}

.. or instead of a comma separated list, an array. Afterwards I would condition it with !is_admin() to only trim the rest publicly.

Describe alternatives you've considered
I did thought about using elementor/frontend/print_google_fonts filter to disable and continue "my way", but i couldn't find any hook or public list of fonts in Frontend class.

Additional context
Refs: #2088 #4624

PS: if i'd have a green light i could pull request that in no time :)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions