Skip to content

Instantly share code, notes, and snippets.

View ian-svoboda-prom's full-sized avatar

Ian Svoboda ian-svoboda-prom

  • Promenade
  • Jacksonville, FL
View GitHub Profile
@ian-svoboda-prom
ian-svoboda-prom / get-svg.php
Created April 17, 2023 10:56
PHP functions to retrieve an SVG file and load it inline. Also supports adding new attributes to the SVG that aren't already there.
<?php
function get_html_attributes(array $atts) {
return array_reduce($atts, function($carry, $name) use($atts) {
$value = $atts[$name];
return "$carry $name=\"$value\"";
});
}
function get_svg( string $name, array $atts = [] ) : string {
$file = get_template_directory() . "/dist/images/$name.svg";
@ian-svoboda-prom
ian-svoboda-prom / async-enqueues.php
Last active May 12, 2023 10:24
Apply async/non-blocking loading to link tags in WordPress
<?php
/**
* Inpspired by Scott Jehl: https://www.filamentgroup.com/lab/load-css-simpler/
*
**/
add_action( 'style_loader_tag', 'async_preload_stylesheets', 99, 4 );
function async_preload_stylesheets( string $tag, string $handle, string $href, string $media ) : string {
// Add the stylesheet handles you want to load async
$allowlist = [ 'your-stylesheet-handle' ];