Skip to content

Instantly share code, notes, and snippets.

@henshaw
henshaw / homebrew-install.sh
Created May 4, 2025 16:11
Script for installing Homebrew
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
@henshaw
henshaw / breadcrumbe-schema.php
Created May 4, 2025 02:31
WordPress functions for dynamically inserting data into BreadcrumbList schema markup
// For category ListItem
"@id": "<?php echo $cat_link ?>"
"name": "<?php echo get_the_category( $id )[0]->name; ?>"
// For post ListItem
"@id": "<?php the_permalink(); ?>"
"name": "<?php the_title(); ?>"
@henshaw
henshaw / article-schema.php
Created May 4, 2025 02:30
WordPress functions for dynamically inserting data into Article schema markup
"@id": "<?php the_permalink(); ?>"
"headline": "<?php the_title(); ?>"
"description": "<?php echo get_the_excerpt(); ?>"
"datePublished": "<?php the_time('c'); ?>"
"dateModified": "<?php the_modified_time('c'); ?>"
// For author type
"name": "<?php the_author(); ?>"
"url":"<?php echo get_the_author_meta('user_url'); ?>"
// For image type
"url": "<?php if ( has_post_thumbnail() ) { the_post_thumbnail_url( 'full' ); } ?>"
@henshaw
henshaw / lazy-loading-image.html
Created May 4, 2025 02:29
Lazy loading an image
<img src="https://domain.com/image.png” loading="lazy" alt="Image description">
@henshaw
henshaw / prefetch-js.html
Created May 4, 2025 02:27
Prefetch used for resource hints
<link rel="prefetch" href="script.js" as="script">
@henshaw
henshaw / async-script.html
Created May 4, 2025 02:26
Loading JavaScript asynchronously
<script async src="script.js">
@henshaw
henshaw / exclude-css.php
Created May 4, 2025 02:25
Exclude CSS not used on the page
<?php if (is_front_page()) : ?> CSS only for homepage <?php elseif (is_category(1)) : ?> CSS only for category with ID 1 <?php elseif (is_category(2)) : ?> ... <?php endif; ?>
@henshaw
henshaw / preload-css.html
Created May 4, 2025 02:24
Defering CSS that isn't required for the initial render
<link rel="preload" href="path/to/stylesheet.css" as="style" onload="this.rel='stylesheet'">
@henshaw
henshaw / css.php
Created May 4, 2025 02:22
PHP for including a CSS file in a WordPress template
<style><?php include_once( 'app.css.php' ); ?></style>
@henshaw
henshaw / font-display.css
Created May 4, 2025 02:19
Font display options
font-display:swap;
font-display:optional;