PHPackages                             wptt/webfont-loader - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [File &amp; Storage](/categories/file-storage)
4. /
5. wptt/webfont-loader

ActivePackage[File &amp; Storage](/categories/file-storage)

wptt/webfont-loader
===================

Locally host webfonts.

v1.1.4(1y ago)12651.7k↓30%1[10 issues](https://github.com/WPTT/webfont-loader/issues)2MITPHPPHP &gt;=5.6

Since Sep 25Pushed 1y ago14 watchersCompare

[ Source](https://github.com/WPTT/webfont-loader)[ Packagist](https://packagist.org/packages/wptt/webfont-loader)[ Docs](https://github.com/WPTT/font-loader)[ RSS](/packages/wptt-webfont-loader/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (7)Dependencies (4)Versions (8)Used By (2)

Webfonts Loader
===============

[](#webfonts-loader)

Downloads webfonts (like for example Google-Fonts), and hosts them locally on a WordPress site.

This improves performance (fewer requests to multiple top-level domains) and increases privacy. Since fonts get hosted locally on the site, there are no pings to a 3rd-party server to get the webfonts and therefore no tracking.

Usage
-----

[](#usage)

A WordPress theme will typically enqueue assets using the [`wp_enqueue_style`](https://developer.wordpress.org/reference/functions/wp_enqueue_style/) function:

```
function my_theme_enqueue_assets() {
	// Load the theme stylesheet.
	wp_enqueue_style(
		'my-theme',
		get_stylesheet_directory_uri() . '/style.css',
		array(),
		'1.0'
	);
	// Load the webfont.
	wp_enqueue_style(
		'literata',
		'https://fonts.googleapis.com/css2?family=Literata&display=swap',
		array(),
		'1.0'
	);
}
add_action( 'wp_enqueue_scripts', 'my_theme_enqueue_assets' );
```

To locally host the webfonts, you will first need to download the [`wptt-webfont-loader.php`](https://raw.githubusercontent.com/WPTT/font-loader/master/wptt-webfont-loader.php) file from this repository and copy it in your theme. Once you do that, the above code can be converted to this:

```
function my_theme_enqueue_assets() {
	// Include the file.
	require_once get_theme_file_path( 'inc/wptt-webfont-loader.php' );
	// Load the theme stylesheet.
	wp_enqueue_style(
		'my-theme',
		get_stylesheet_directory_uri() . '/style.css',
		array(),
		'1.0'
	);
	// Load the webfont.
	wp_enqueue_style(
		'literata',
		wptt_get_webfont_url( 'https://fonts.googleapis.com/css2?family=Literata&display=swap' ),
		array(),
		'1.0'
	);
}
add_action( 'wp_enqueue_scripts', 'my_theme_enqueue_assets' );
```

Available functions
-------------------

[](#available-functions)

### `wptt_get_webfont_styles`

[](#wptt_get_webfont_styles)

```
$remote_url = 'https://fonts.googleapis.com/css2?family=Literata&display=swap';
$contents   = wptt_get_webfont_styles( $remote_url );

```

Returns the stylesheet contents, using locally hosted webfonts.

### `wptt_get_webfont_url`

[](#wptt_get_webfont_url)

```
$remote_url = 'https://fonts.googleapis.com/css2?family=Literata&display=swap';
$contents   = wptt_get_webfont_url( $remote_url );

```

Returns a stylesheet URL, locally-hosted.

Build url for multiple fonts
----------------------------

[](#build-url-for-multiple-fonts)

```
$font_families = array(
	'Quicksand:wght@300;400;500;600;700',
	'Work+Sans:wght@300;400;500;600;700'
);

$fonts_url = add_query_arg( array(
	'family' => implode( '&family=', $font_families ),
	'display' => 'swap',
), 'https://fonts.googleapis.com/css2' );

$contents = wptt_get_webfont_url( esc_url_raw( $fonts_url ) );
```

Supporting IE
-------------

[](#supporting-ie)

The `wptt_get_webfont_url` will - by default - download `.woff2` files. However, if you need to support IE you will need to use `.woff` files instead. To do that, you can pass `woff` as the 2nd argument in the `wptt_get_webfont_url` function:

```
wptt_get_webfont_url( 'https://fonts.googleapis.com/css2?family=Literata&display=swap', 'woff' );
```

Storing In A Custom Directory
-----------------------------

[](#storing-in-a-custom-directory)

If you have the need to store font files in a custom directory you can pass a custom path and URL using filters. Be sure you add these filters **BEFORE** the file containing the `WPTT_WebFont_Loader` class is called.

```
/**
 * Change the base path.
 * This is by default WP_CONTENT_DIR.
 *
 * NOTE: Do not include trailing slash.
 */
add_filter( 'wptt_get_local_fonts_base_path', function( $path ) {
	return WP_CONTENT_DIR;
} );

/**
 * Change the base URL.
 * This is by default the content_url().
 *
 * NOTE: Do not include trailing slash.
 */
add_filter( 'wptt_get_local_fonts_base_url', function( $url ) {
	return content_url();
} );

/**
 * Change the subfolder name.
 * This is by default "fonts".
 *
 * Return empty string or false to not use a subfolder.
 */
add_filter( 'wptt_get_local_fonts_subfolder_name', function( $subfolder_name ) {
	return 'fonts';
} );
```

###  Health Score

40

—

FairBetter than 88% of packages

Maintenance34

Infrequent updates — may be unmaintained

Popularity42

Moderate usage in the ecosystem

Community21

Small or concentrated contributor base

Maturity54

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 67.7% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~246 days

Recently: every ~368 days

Total

7

Last Release

582d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/471c510b2590bce99d5e41cc9b817f0c0d420f08d0930e70b18299f993ffa965?d=identicon)[aristath](/maintainers/aristath)

---

Top Contributors

[![aristath](https://avatars.githubusercontent.com/u/588688?v=4)](https://github.com/aristath "aristath (21 commits)")[![pattonwebz](https://avatars.githubusercontent.com/u/3902039?v=4)](https://github.com/pattonwebz "pattonwebz (5 commits)")[![mircobabini](https://avatars.githubusercontent.com/u/636911?v=4)](https://github.com/mircobabini "mircobabini (2 commits)")[![webmandesign](https://avatars.githubusercontent.com/u/2456735?v=4)](https://github.com/webmandesign "webmandesign (2 commits)")[![dingo-d](https://avatars.githubusercontent.com/u/8638515?v=4)](https://github.com/dingo-d "dingo-d (1 commits)")

---

Tags

wordpress

### Embed Badge

![Health badge](/badges/wptt-webfont-loader/health.svg)

```
[![Health](https://phpackages.com/badges/wptt-webfont-loader/health.svg)](https://phpackages.com/packages/wptt-webfont-loader)
```

###  Alternatives

[humanmade/network-media-library

Network Media Library provides a central media library that's shared across all sites on the Multisite network.

29644.8k](/packages/humanmade-network-media-library)[ilab/ilab-media-tools

Tools for cropping, uploading to S3, serving through Imgix

119102.7k1](/packages/ilab-ilab-media-tools)[dre1080/wp-graphql-upload

Adds file upload support to the WP GraphQL Plugin.

3854.0k](/packages/dre1080-wp-graphql-upload)[mcguffin/acf-dropzone

Drag and drop file upload for ACF-Fields.

339.2k](/packages/mcguffin-acf-dropzone)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
