Skip to content

Instantly share code, notes, and snippets.

@henshaw
henshaw / post-title-excerpt.php
Created January 2, 2024 23:55
WordPress code for post title and excerpt
<h1><?php the_title(); ?></h1>
<?php echo '<p>' . get_the_excerpt() . '</p>'; ?>
@henshaw
henshaw / schema-profilepage.js
Last active November 29, 2023 05:26
Detailed ProfilePage Schema example
<script type="application/ld+json">
{
"@context": "https://schema.org",
"@type": "ProfilePage",
"dateCreated": "2019-12-23T12:34:00-05:00",
"dateModified": "2019-12-26T14:53:00-05:00",
"mainEntity": {
"@type": "Person",
"@id": "https://www.coywolf.news/jon-henshaw#Person",
"name": "Jon Henshaw",
@henshaw
henshaw / rei-sponsored-pattern-matching.js
Created October 29, 2023 17:08
Pattern matching event tracking with Fathom Analytics
<script>
document.querySelectorAll('[rel="sponsored"]').forEach(item => {
item.addEventListener('click', event => {
let linkUrl = new URL(item.getAttribute('href'), window.location.href);
// Using the second argument to handle relative URLs
let currentHostname = window.location.hostname;
if (linkUrl.hostname !== currentHostname) {
// If the link's hostname is different from the current page's hostname
let domainParts = linkUrl.hostname.split('.');
let domainName = domainParts.length > 1 ? domainParts[domainParts.length - 2] : domainParts[0];
@henshaw
henshaw / lazy-loading-image.html
Created October 4, 2023 21:31
Native image lazy loading
<img src="https://domain.com/image.png" loading="lazy" alt="Image description">
@henshaw
henshaw / google-extended-folder.txt
Created September 29, 2023 05:31
Disallow specific folders from being used to train Google LLMs
User-agent: Google-Extended
Disallow: /folder
@henshaw
henshaw / google-extended-all.txt
Created September 29, 2023 05:30
Disallow all pages from being used to train Google LLMs
User-agent: Google-Extended
Disallow: /
@henshaw
henshaw / rss-feed-link-example.html
Created September 16, 2023 17:25
RSS feed link example
@henshaw
henshaw / gravatar-alt-text.php
Last active September 3, 2023 01:31
Add ALT text to gravatar image in byline
// If you use this Gravatar code in your WordPress templates
<?php echo get_avatar( get_the_author_meta( 'ID' ), 60); ?>
// Add this to functions.php to include ALT text with the image
function gravatar_alt($text) {
$alt = get_the_author_meta( 'display_name' );
$text = str_replace('alt=\'\'', 'alt=\'Headshot for '.$alt.'\'',$text);
return $text;
}
add_filter('get_avatar','gravatar_alt');
@henshaw
henshaw / block-cloudflare-stream.php
Last active September 2, 2023 05:47
VideoObject Schema structured data for Cloudflare Stream videos in WordPress. To be used with Genesis Custom Blocks plugin.
<script type="application/ld+json">
{
"@context": "https://schema.org",
"@type": "VideoObject",
"name": "<?php block_field( 'cs-name' ); ?>",
"description": "<?php block_field( 'cs-description' ); ?>",
"thumbnailUrl": "<?php block_field( 'cs-thumbnail' ); ?>",
"uploadDate": "<?php the_time('c'); ?>",
"duration": "PT<?php $cshours = block_field( 'cs-hours', false ); if ( ! empty( $cshours ) ) { echo $cshours . 'H'; } ?><?php $csminutes = block_field( 'cs-minutes', false ); if ( ! empty( $csminutes ) ) { echo $csminutes . 'M'; } ?><?php $csseconds = block_field( 'cs-seconds', false ); if ( ! empty( $csseconds ) ) { echo $csseconds . 'S'; } ?>",
"embedUrl": "https://<?php block_field( 'cs-subdomain' ); ?>/<?php block_field( 'cs-id' ); ?>/iframe"
@henshaw
henshaw / schema-person.js
Last active August 28, 2023 23:18
Detailed Person Schema example
<script type="application/ld+json">
{
"@context": "https://schema.org",
"@type": "Person",
"@id": "https://www.coywolf.news/jon-henshaw#Person",
"name": "Jon Henshaw",
"givenName": "Jonathan",
"familyName": "Henshaw",
"additionalName": "Michael",
"nationality":{