Skip to content

Instantly share code, notes, and snippets.

@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 / 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 / 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
*
<?php
class ACF_Product_Options {
static $slug = 'hwid_attributes';
public static function init() {
// Gather the global attribute types
$attribute_terms = wc_get_attribute_taxonomy_names();
@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 / gforms-merge-tag.php
Last active November 3, 2023 06:12
Create a custom Gravity Forms merge tag
<?php
namespace HWID\SampleCode;
class GravityForms {
public static function init() {
add_filter( 'gform_custom_merge_tags', [ 'HWID\SampleCode\GravityForms', 'custom_merge_tags' ], 10, 4 );
add_filter( 'gform_replace_merge_tags', [ 'HWID\SampleCode\GravityForms', 'replace_merge_tags' ], 10, 3 );
}
/**
@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 / archive-commit.bat
Last active November 25, 2022 03:55
Create a zip archive of a specific commit. The archive will be named deploy/deploy-COMMITID.zip.
setlocal enabledelayedexpansion
set var=%1
set output=
for /f "delims=" %%a in ('git diff-tree --no-commit-id --name-only -r %1^^') do ( set output=!output! "%%a" )
git archive -o update-%var:~0,7%.zip HEAD %output%
endlocal
@hereswhatidid
hereswhatidid / custom-acf-wysiwyg-css.php
Last active September 27, 2022 15:27
Applies defined CSS classes to the ACF WYSIWYG editor so that you can individually style them.
<?php
function hwid_acf_admin_footer() {
?>
<script>
( function( $) {
acf.add_filter( 'wysiwyg_tinymce_settings', function( mceInit, id ) {
// grab the classes defined within the field admin and put them in an array
var classes = $( '#' + id ).closest( '.acf-field-wysiwyg' ).attr( 'class' );
@hereswhatidid
hereswhatidid / acf-wysiwyg-body-class.php
Created August 12, 2015 20:30
Adds a custom class to a specific WYSIWYG editor within Advanced Custom Fields.
<?php
function my_acf_admin_footer() {
?>
<script>
( function( $) {
acf.add_filter( 'wysiwyg_tinymce_settings', function( mceInit, id ) {
if ( id === 'special-wysiwyg-field' ) {
mceInit.body_class += ' magical-field-class';
}
return mceInit;