Skip to content

Instantly share code, notes, and snippets.

@hellofromtonya
Created April 19, 2022 13:21
Show Gist options
  • Save hellofromtonya/3f7cb383b7b318502489df501c6185b0 to your computer and use it in GitHub Desktop.
Save hellofromtonya/3f7cb383b7b318502489df501c6185b0 to your computer and use it in GitHub Desktop.
Test Plugin that programmatically registers a normal and italic Source Sans Pro with the Webfonts API
<?php
/**
Plugin Name: Test Webfonts
Plugin URI: http://wordpress.org/plugins/test-plugin/
Description: Testing programmatically register webfonts from a plugin.
Author: me
Version: 1.0
*/
add_action(
'after_setup_theme',
function() {
$webfonts = array(
array(
'font-family' => 'Source Sans Pro',
'font-style' => 'normal',
'font-stretch' => 'normal',
'font-weight' => '400',
'src' => 'http://localhost:8889/src/wp-content/plugins/test-plugin-webfonts/assets/fonts/SourceSansPro-Regular.ttf',
),
array(
'font-family' => 'Source Sans Pro',
'font-style' => 'normal',
'font-stretch' => 'italic',
'font-weight' => '400',
'src' => 'http://localhost:8889/src/wp-content/plugins/test-plugin-webfonts/assets/fonts/SourceSansPro-Italic.ttf',
)
);
wp_register_webfonts( $webfonts );
},
99
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment