Skip to content

Instantly share code, notes, and snippets.

View grayayer's full-sized avatar

Gray Ayer grayayer

View GitHub Profile
@grayayer
grayayer / fix-strong-headings.php
Last active March 21, 2026 22:02
A WP-CLI script that removes `<strong>` and `<b>` tags that wrap either partial or the entire content of an `h1`–`h5` heading inside Gutenberg block editor posts.
<?php
/**
* fix-strong-headings.php
*
* Removes <strong> and <b> tags from inside h1–h5 headings in Gutenberg
* block editor posts of a given post type.
*
* Two modes, both always active together when PARTIAL_STRONG is true:
*
* Full-wrap (always on):
@grayayer
grayayer / gist:1dfa56478225466156b234567fd9f393
Created March 16, 2026 17:58
Add paragraph break after colon in post titles on wordpress single post pages.
/**
* Add paragraph break after colon in post titles on single post pages.
*
* @param string $title The post title.
* @return string Modified title with paragraph break after colon if applicable.
*/
function modify_post_title_with_colon( $title ) {
// Only modify title on single post pages.
if ( is_single() && in_the_loop() && is_main_query() ) {
// Replace colon with colon + paragraph break.

WordPress Image Resize Script

A WordPress utility script that automatically converts full-resolution images in Gutenberg blocks to optimized sizes (medium or large).

What It Does

This script scans all posts in your WordPress site and finds Gutenberg image blocks that are using full-resolution images. It then converts them to use a specified size (medium or large), updating both the image URL and block attributes.

When To Use This

@grayayer
grayayer / instructions on using verify redirect script
Last active April 15, 2025 17:50
Takes your domain list file as input Tests each domain to see if it properly redirects to your target
Creates a timestamped report file (e.g., redirect_verification_report_20250415_120530.txt)
Records all failures, timeouts, and errors in the report file
Includes detailed information about each issue
Adds a summary section at the end of the report
Automatically deletes the report file if all redirects work correctly (no failures or errors)
Provides a clear message about where to find the report if issues are detected
When you run this script:
If everything works perfectly, you'll see a success message and no report file will be created
@grayayer
grayayer / gist:866f8812c562754c2b401b0c906061fa
Created November 6, 2024 00:43
allow wordpress password protected pages to show users what they're typing in the password field when it's focused
<?php
/**
* Password Peek
*
* Add focus toggle script to password-protected pages, so when the password field is focused, it will show the password.
*
* @package PDXWLF
*/
/**
@grayayer
grayayer / Solo Custom GA4 Events
Created July 12, 2024 21:39
This provides extra data that GA4 doesn't provide on it's own.
// Global Constants to use throughout the script
const pageTitle = document.title;
const pageUrl = window.location.href;
window.addEventListener('load', () => {
//## FORMS ###
const forms = document.querySelectorAll('form:not([data-type="search"])');
if([...forms].length > 0){
@grayayer
grayayer / archive-coverage.php
Created May 14, 2024 00:54
The WP archive template for the CPT Media Coverage for Solo.io
<?php get_header();
$year = get_query_var('year');
$posts_args = array(
'post_type' => 'coverage',
'posts_per_page' => -1, // Show all posts
'orderby' => 'date',
'order' => 'DESC',
'date_query' => array(
@grayayer
grayayer / archive-rewrites.php
Created May 14, 2024 00:51
these are rewrite rules required to make the year filter work on the news archives
//** Custom Post Type Archive Rewrite Rules **//
function custom_news_rewrite_rules($rules) {
$new_rules = [
'company/news-room/media-coverage/([0-9]{4})/?$' => 'index.php?post_type=coverage&year=$matches[1]',
'our-news/([0-9]{4})/?$' => 'index.php?post_type=news&year=$matches[1]'
];
// This places your new rule at the top of the array to ensure it has priority.
return $new_rules + $rules;
}
@grayayer
grayayer / better-acf-image.php
Last active December 22, 2024 20:15
create a picture element from an either an array or URL. Useful for when one is using ACF for calling images instead of through native WP mechanism
/* CREATE A PICTURE ELEMENT FROM AN ACF IMAGE FIELD, IF DATA IS either an array or URL
TO DO:
- pass src set for truly responsive images using the ID as the ACF data.
*/
// Check for .webp existence
function webp_exists($image_url) {
$upload_dir = wp_upload_dir();
$relative_path = str_replace($upload_dir['baseurl'], '', $image_url);
$webp_path = $upload_dir['basedir'] . $relative_path . '.webp';
@grayayer
grayayer / auto-click gift woocommerce subscription
Created December 1, 2020 04:26
WooCommerce Subscription product page with gifted subscriptions checkbox gets auto clicked upon page load.
function auto_select_gift() {
if ( is_single(56669) ) { //enter product id here
?>
<script type="text/javascript">
jQuery(document).ready(function ($) {
document.getElementById("gifting_0_option").click(); // Click on the checkbox
});
</script>
<?php