Skip to content

Instantly share code, notes, and snippets.

View greghunt's full-sized avatar

Greg Hunt greghunt

View GitHub Profile
@greghunt
greghunt / submit-select-change.html
Created April 24, 2023 15:49
Submit form on select change
<select onchange="this.form.submit()">
<option>...</option>
</select>
@greghunt
greghunt / iswp.sh
Created February 21, 2022 00:37
Super Simple WordPress Site Test
#!/bin/bash
if [[ "$(curl -L -s $1/license.txt | grep -coF WordPress)" -gt 0 ]]; then
echo "Is WordPress"
else
echo "Is NOT WordPress"
fi
@greghunt
greghunt / convert-images-webp.sh
Created November 15, 2022 14:27
Batch Convert WEBP images
#!/bin/bash
# converting JPEG images
find $1 -type f -and \( -iname "*.jpg" -o -iname "*.jpeg" \) \
-exec bash -c '
webp_path=$(sed 's/\.[^.]*$/.webp/' <<< "$0");
if [ ! -f "$webp_path" ]; then
cwebp -quiet -q 90 "$0" -o "$webp_path";
fi;' {} \;
@greghunt
greghunt / generate-blocks-template-part-css.php
Created June 18, 2022 23:48
Generate CSS for Generate Block used outside of the page
<?php
add_filter('generateblocks_do_content', function ($content) {
$part = 'page-header';
$template_part = get_block_template(get_stylesheet() . '//' . $part, 'wp_template_part');
if ($extra = $template_part->content) {
$content = $extra . $content;
}
@greghunt
greghunt / scroll-to.js
Last active November 11, 2021 15:22
Scroll to a section
document.querySelectorAll("[data-scroll]").forEach(el => {
el.addEventListener('click', () => document.querySelector(el.dataset.scroll).scrollIntoView(true));
});
@greghunt
greghunt / nyt-paywall-bypass.js
Created November 2, 2021 22:56
By-pass New York Times Pay Wall Article
var w = window.open("Article", "blank"); var content = Array.prototype.map.call(document.querySelectorAll('.StoryBodyCompanionColumn'), ( el ) => `<p>${el.textContent}</p>` ).join(''); w.document.write(`<link rel="stylesheet" href="https://unpkg.com/tailwindcss@1.4.6/dist/base.min.css"><link rel="stylesheet" href="https://unpkg.com/tailwindcss@1.4.6/dist/components.min.css"><link rel="stylesheet" href="https://unpkg.com/@tailwindcss/typography@0.1.2/dist/typography.min.css"><link rel="stylesheet" href="https://unpkg.com/tailwindcss@1.4.6/dist/utilities.min.css"><body class="prose mx-auto my-20">${content}</body>`); w.document.close();
@greghunt
greghunt / data-tabs.js
Last active June 10, 2021 14:10
Vanilla Javascript Tabbing System
function chooseTab( tabEl ) {
const activeClasses = tabEl.getAttribute('data-tab-active-class').split(" ");
const name = tabEl.getAttribute('data-tab');
const tabGroup = tabEl.closest('[data-tabs]');
tabGroup.querySelectorAll('[data-tab]').forEach(el =>
el == tabEl ? el.classList.add(...activeClasses) : el.classList.remove(...activeClasses)
)
tabGroup.querySelectorAll('[data-tab-name]').forEach(el =>
@greghunt
greghunt / functions.php
Created April 18, 2018 15:04 — forked from mustardBees/functions.php
Filter a few parameters into WordPress YouTube oEmbed requests. Enable modest branding which hides the YouTube logo. Remove the video title and uploader information. Prevent related videos from being shown once the video has played.
<?php
/**
* Filter a few parameters into YouTube oEmbed requests
*
* @link http://goo.gl/yl5D3
*/
function iweb_modest_youtube_player( $html, $url, $args ) {
return str_replace( '?feature=oembed', '?feature=oembed&modestbranding=1&showinfo=0&rel=0', $html );
}
add_filter( 'oembed_result', 'iweb_modest_youtube_player', 10, 3 );
@greghunt
greghunt / featured-image.php
Created December 4, 2018 23:11
WordPress Featured Image Src
@greghunt
greghunt / Shortcodes.php
Created October 10, 2018 12:23
Simple class for organizing and registering your WordPress shortcodes.
<?php
namespace App;
class Shortcodes {
protected $shortcodes = [];
public function __construct()
{