Skip to content

Instantly share code, notes, and snippets.

@greghunt
greghunt / convert-images-webp.sh
Created November 15, 2022 14:27
Batch Convert WEBP images
View convert-images-webp.sh
#!/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
View generate-blocks-template-part-css.php
<?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 / iswp.sh
Created February 21, 2022 00:37
Super Simple WordPress Site Test
View iswp.sh
#!/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 / nyt-paywall-bypass.js
Created November 2, 2021 22:56
By-pass New York Times Pay Wall Article
View nyt-paywall-bypass.js
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
View data-tabs.js
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 / featured-image.php
Created December 4, 2018 23:11
WordPress Featured Image Src
View featured-image.php
@greghunt
greghunt / Shortcodes.php
Created October 10, 2018 12:23
Simple class for organizing and registering your WordPress shortcodes.
View Shortcodes.php
<?php
namespace App;
class Shortcodes {
protected $shortcodes = [];
public function __construct()
{
@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.
View functions.php
<?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 / autosubmit.js
Created March 12, 2018 14:40
Auto-submit a form
View autosubmit.js
$("[data-autosubmit]").on('change', function(){
$(this).parents("form").submit();
});
@greghunt
greghunt / get-filtering.php
Last active March 12, 2018 14:43
Add GET based filtering of WordPress queries.
View get-filtering.php
<?php
/**
* Allow filtering of index/archives by GET
* Example) Adding ?sort=-date will sort posts descending by date.
* Possible Values: https://codex.wordpress.org/Class_Reference/WP_Query#Order_.26_Orderby_Parameters
*/
add_action('pre_get_posts', function ($query) {
if( $query->is_main_query() ) {
$sort = "relevance";
$order = "DESC";