Skip to content

Instantly share code, notes, and snippets.

Avatar

Leesa Ward doubleedesign

View GitHub Profile
@doubleedesign
doubleedesign / breadcrumbs-list.php
Created Dec 4, 2018
Mark up Yoast breadcrumbs as an unordered list
View breadcrumbs-list.php
<?php
/**
* Filter the output of Yoast breadcrumbs so each item is an <li> with schema markup
* @param $link_output
* @param $link
*
* @return string
*/
function doublee_filter_yoast_breadcrumb_items( $link_output, $link ) {
@doubleedesign
doubleedesign / acf-tsf-integration.php
Last active Aug 17, 2022
Get meta descriptions in The SEO Framework from ACF flexible content fields
View acf-tsf-integration.php
<?php
/**
* The SEO Framework + ACF flexible content integration
* TSF will look at the excerpt and then the content to generate the default meta description.
* If both of those are empty, this code looks for ACF flexible modules to get it from.
* // TODO: Make this work with archives as well as posts
* @param $description
* @param $args
*
* @return mixed|string
@doubleedesign
doubleedesign / checkout-functions.php
Created May 17, 2019
Add reCaptcha v2 to WooCommerce Checkout
View checkout-functions.php
<?php
/**
* Add reCaptcha to checkout form
* Note: Can't place within the payment part of the form, WooCommerce just won't show it, choose an appropriate action to add it to accordingly
* @param $checkout
*/
function doublee_show_me_the_checkout_captcha($checkout) {
echo '<div class="g-recaptcha" data-sitekey="YOUR_KEY_HERE"></div>';
}
add_action('woocommerce_checkout_order_review', 'doublee_show_me_the_checkout_captcha', 18);
@doubleedesign
doubleedesign / widget-product-categories.php
Created Jan 17, 2021
Override the output of the WooCommerce product categories widget to be a Bootstrap accordion
View widget-product-categories.php
<?php
/**
* Product Categories Widget
* Modifies the WooCommerce product categories widget to display as a Bootstrap accordion.
*
* @package WooCommerce/Widgets
* @version 2.3.0
*/
defined( 'ABSPATH' ) || exit;
@doubleedesign
doubleedesign / YearbookClasses.jsx
Last active Oct 24, 2021
InDesign Image Catalog for multiple folders at once (and multiple folders per page). Created for school yearbook projects (one folder per class, two classes per page) but could be adapted for other use cases where you want to lay out contact sheets of multiple folders automatically.
View YearbookClasses.jsx
/**
* Custom Image Catalog script that runs for all subfolders in a selected folder.
* Lays out each folder of images in the specified number of rows and columns, 2 folders per page, shows an alert if there's more images than allowed for,
* labels each group with the folder name, creates paragraph styles for the captions and group headings, and saves the file.
*
* Based on the built-in Image Catalog script but modified and simplified (e.g. hard-coding the settings) for my use case.
* Could be modified to suit different numbers of folders per page, different image quantities etc by changing the settings at the top
* and making tweaks to other code as needed.
*
* Could also be extended to show one dialog for settings prior to the loop,
@doubleedesign
doubleedesign / javascript-delayed-event.js
Created Dec 9, 2018
How to delay a JavaScript event within an event listener
View javascript-delayed-event.js
function myDelayedThing() {
var mySelectors = document.querySelectorAll('.something');
// Loop through mySelectors
for(var i = 0; i < menuLinks.length; i++) {
// Add 'open' class on mouseover
menuLinks[i].addEventListener('mouseover', function() {
this.classList.add('open');
@doubleedesign
doubleedesign / cpt-case_study.php
Created Jun 28, 2021
Use a WooCommerce product attribute taxonomy for a custom post type
View cpt-case_study.php
<?php
// Register Custom Post Type
// Note: Using woocommerce_after_register_taxonomy hook instead of init because we're using a product attribute taxonomy with this CPT
function doublee_cpt_case_study() {
$labels = array(
'name' => _x('Case studies', 'Post Type General Name', 'doubleedesign'),
'singular_name' => _x('Case study', 'Post Type Singular Name', 'doubleedesign'),
'menu_name' => __('Case studies', 'doubleedesign'),
'name_admin_bar' => __('Case study', 'doubleedesign'),
@doubleedesign
doubleedesign / functions.php
Created Apr 28, 2021
Log all WordPress hooks that run
View functions.php
<?php
function doublee_log_all_actions() {
foreach($GLOBALS['wp_actions'] as $action => $count) {
error_log(print_r($action, true));
}
}
add_action('shutdown', 'doublee_log_all_actions');
@doubleedesign
doubleedesign / convert-milliseconds.js
Last active Apr 22, 2021
Timed pop-up using Zurb Foundation Reveal (modal); stores whether the user has dismissed it or already subscribed in local storage. This example is built in WordPress using ACF to get values of what to store, when to show up etc (and Ninja Forms for the form but of course it doesn't have to be used for a form).
View convert-milliseconds.js
/**
* Convert milliseconds to the desired format
* @param milliseconds
* @param format
* @returns {*}
* @see https://gist.github.com/flangofas/714f401b63a1c3d84aaa
*/
function convertMilliseconds(milliseconds, format) {
var total_days, total_hours, total_minutes, total_seconds;
@doubleedesign
doubleedesign / _export-orders.php
Last active Jan 18, 2021
Export selected data about the currently shown WooCommerce orders to a CSV file
View _export-orders.php
<?php
/**
* Function to export the orders list to a CSV download (not stored anywhere)
* CSV construction based on https://gist.github.com/vrushank-snippets/4274500
* Dev notes:
* - This file is designed to be called via AJAX, with that function providing the order IDs.
* - To use this without AJAX you would just need to define $order_ids = wp_list_pluck($wp_query->posts, 'ID') instead,
* and define $filename as something appropriate here.
*/
function doublee_export_orders() {