Skip to content

Instantly share code, notes, and snippets.

@henshaw
henshaw / google-web-cache.js
Created January 29, 2024 04:09
Bookmarklet URL for viewing a web page in Google's Web Cache
javascript: window.location = 'https://webcache.googleusercontent.com/search?q=cache:' + window.location.protocol + '//' + window.location.hostname + window.location.pathname;
@henshaw
henshaw / hide-label.css
Last active January 25, 2024 23:32
CSS for hiding the WordPress Search Form Label while maintaining accessiblity (not using display:none;)
.screen-reader-text:not(:focus):not(:active) {
position: absolute;
overflow: hidden;
clip: rect(0 0 0 0);
clip-path: inset(50%);
width: 1px;
height: 1px;
white-space:nowrap;
}
@henshaw
henshaw / open-graph-image.php
Created January 3, 2024 00:02
Open Graph Thumbnail Images for WordPress
if ( function_exists( 'add_theme_support' ) ) {
add_theme_support( 'post-thumbnails' );
set_post_thumbnail_size( 150, 79, true );
add_image_size( 'single-post-thumbnail', 1200, 630 );
}
@henshaw
henshaw / remove-yoast-schema.php
Created January 3, 2024 00:01
Remove Yoast Schema output from WordPress
function remove_yoast_json($data){
$data = array();
return $data;
}
add_filter('wpseo_json_ld_output', 'remove_yoast_json', 10, 1);
@henshaw
henshaw / author-bio.php
Created January 3, 2024 00:00
Add a short author bio at the end of the articles
<?php echo get_the_author_meta('description'); ?>
@henshaw
henshaw / article-timestamp.php
Created January 2, 2024 23:59
Dynamically inserting the article timestamp in WordPress
<time datetime="<?php the_time('c'); ?>"><?php the_time('m/j/Y'); ?> <?php the_time('g:ia T'); ?></time>
@henshaw
henshaw / author-url.php
Created January 2, 2024 23:57
Dynamically inserting the author’s URL in WordPress
<a href="<?php echo get_the_author_meta('user_url'); ?>"><?php the_author(); ?></a>
@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];