Skip to content

Instantly share code, notes, and snippets.

View grayayer's full-sized avatar

Gray Ayer grayayer

View GitHub Profile
@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
Search for : (.*(\n|$)){2}
alt+R - to toggle regular expression search
alt+ENTER - to select all results
@grayayer
grayayer / user_favorites.js
Last active July 10, 2020 22:17
This is a jquery/javascript that allows us to change the visible status of a "liked" status of an element, then store that preference in a user's browser so that the changed state remains upon returning to the page. This was built specifically for http://moda2.studiok40.com/index-moda.html but can be modified for anyone else's purposes
/** SCRIPTS FOR DESIGNATING WHEN ITEMS ARE LIKED, STORING THAT PREFERENCE,
AND LOADING THOSE PREFERENCES UPON PAGE REFRESH **/
/** when you click on a featured heart, make it liked **/
$(".solution_item .liked_status").click(function(){
// create a variable that references the containing parent of heart just clicked
const self = $(this).parent();
// create a variable that contains just the ID of the parent element
const likedToolID = self.attr("id");
@grayayer
grayayer / woocommerce_conditonal_product_purchase_tracking_code.php
Created May 19, 2020 23:15
this function checks whether the page is the order received page, and if so, checks whether the order contains the bundle product, and if so, outputs the tracking pixel on that page. Put this file in your themes function.php file
/** Add tracking pixel if order contains product ID. Replace 11747 with your specific product ID */
add_action( 'woocommerce_thankyou', 'bundleTracking' );
function bundleTracking(){
/* do nothing if we are not on the appropriate page */
if( !is_wc_endpoint_url( 'order-received' ) || empty( $_GET['key'] ) ) {
return;
}