Skip to content

Instantly share code, notes, and snippets.

@henshaw
henshaw / single.json
Last active August 10, 2025 16:53
ReportageNewsArticle Schema.org for WordPress single.php
{
"@context": "http://schema.org",
"@type": "ReportageNewsArticle",
"mainEntityOfPage": {
"@type": "WebPage",
"@id": "<?php the_permalink(); ?>",
"publisher":{
"@type":"NewsMediaOrganization",
"name":"Your Site Name",
"ethicsPolicy":"https://www.yourdomain.com/policies-and-standards/",
@henshaw
henshaw / functions.php
Last active August 3, 2025 20:52
Filters and actions to improve WordPress
<?php
// Disable RSS enclosures for media files
add_filter( 'rss_enclosure', '__return_empty_string' );
// Remove Gutenberg block styles, which I don't use
add_action( 'wp_enqueue_scripts', function() {
wp_dequeue_style( 'wp-block-library' );
} );
@henshaw
henshaw / functions.php
Created June 22, 2025 17:18
Remove Yoast SEO Schema structured data
function remove_yoast_json($data){
$data = array();
return $data;
}
add_filter('wpseo_json_ld_output', 'remove_yoast_json', 10, 1);
@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; ?>