Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@hereswhatidid
hereswhatidid / regenerate-ids.php
Created August 27, 2021 17:05
Pass parameters to Regenerate Thumbnails plugin
<?php
/**
* Preselect the delete old and only missing checkboxes based on the `deleteold` query param
**/
add_filter( 'regenerate_thumbnails_options_onlymissingthumbnails', function( $checked ) {
return ( empty( $_GET['deleteold'] ) && ( $_GET['deleteold'] !== 'yes' ) );
});
add_filter( 'regenerate_thumbnails_options_deleteoldthumbnails', function( $checked ) {
return ( ! empty( $_GET['deleteold'] ) && ( $_GET['deleteold'] === 'yes' ) );
@hereswhatidid
hereswhatidid / wp-limit-srcset.php
Last active April 22, 2024 13:46
Generate the image HTML with a limited srcset range of sizes
<?php
namespace RMG\PageSpeed;
/**
* Get the HTML for an image with limited srcset sizes
*
* @param string|int $image_id
* @param string $size The image size name ex. `medium`, `thumb`
* @param boolean $icon
* @param null|array $attrs
*
@hereswhatidid
hereswhatidid / copy-field.js
Created December 10, 2020 15:19
Copy field value to clipboard
let copyBtn = document.getElementById( 'copyBtn' ),
copyField = document.getElementById( 'fieldID' );
copyBtn.addEventListener( 'click', function( e ) {
e.preventDefault();
copyField.focus();
copyField.select();
document.execCommand( 'copy' );
@hereswhatidid
hereswhatidid / wp-cli-commands.sh
Created June 17, 2020 16:30
Useful wp-cli commands
# list all public taxonomies and the number of entries for each of them
wp taxonomy list --fields=name,label,public,count --public=1
# list all public post types and the number of entries for each of them
wp post-type list --fields=name,label,public,count --public=1
@hereswhatidid
hereswhatidid / yoast-woo-crumbs.php
Last active September 21, 2023 20:59
Integrate Yoast SEO Primary Categories with WooCommerce breadcrumbs
<?php
add_filter( 'woocommerce_breadcrumb_main_term', 'hwid_breadcrumbs_primary_category' );
/**
* Override the default term for WooCommerce cookies if Yoast SEO is installed
*
* @param WP_Term $term
*
* @return WP_Error|WP_Term|null
@hereswhatidid
hereswhatidid / quotation.css
Created November 27, 2019 20:06
Wrap text with directional quotes, quotation, quote marks
.quotation {
&:before {
content: '\201C';
}
&:after {
content: '\201D';
}
}
@hereswhatidid
hereswhatidid / acf-block-preview-action.js
Last active January 23, 2024 12:35
Example ACF block preview action
if( window.acf ) {
window.acf.addAction( 'render_block_preview/type=accordion', function( $elem, blockDetails ) {
initializeElement( $elem );
} );
}
@hereswhatidid
hereswhatidid / Settings.php
Created March 21, 2019 15:48
WooCommerce custom settings page
<?php
namespace RMG\QuoteBuilder;
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
if ( class_exists( 'RMG\QuoteBuilder\Settings_Quotes', false ) ) {
return new Settings_Quotes();
@hereswhatidid
hereswhatidid / custom-gut-category.php
Last active March 8, 2019 19:55
Register custom Gutenberg block category
<?php
function new_category( $categories, $post ) {
return array_merge(
$categories,
array(
array(
'slug' => 'custom-category',
'title' => __( 'Custom Category', 'language' ),
),
)
@hereswhatidid
hereswhatidid / bashrc.sh
Last active February 18, 2019 17:08
Run lighthouse from a bashrc function. ex: "lh https://mynewsite.com"
lh() {
lighthouse "$1" --view --chrome-flags="--headless" --config-path="$HOME/lighthouse-config.js"
}