Skip to content

Instantly share code, notes, and snippets.

View thetwopct's full-sized avatar

James Hunt thetwopct

View GitHub Profile
@thetwopct
thetwopct / image-handling-wordpress.php
Last active March 27, 2023 13:04
WordPress image handling (ACF / Background Images / Inline / srcset /
//
<?php
if ( has_post_thumbnail() ) {
echo wp_get_attachment_image(get_post_thumbnail_id($post->ID), '', false, array('class' => 'featured-image'));
} else {
echo '<img src="' . get_bloginfo( 'stylesheet_directory' )
. '/library/images/thumbnail-default.jpg" alt="default thumb" class="featured-image"/>';
}
?>
@thetwopct
thetwopct / tax-toggle-text.js
Last active March 15, 2023 16:32
Tax Toggle change text of button on click
/**
* Custom code for Tax Toggle for WooCommerce - Changes text of button on click
*
* Based on Tax Toggle for WooCommerce 1.3.6
*
* Plugin: https://1.envato.market/taxtoggle
*
**/
@thetwopct
thetwopct / woocommerce-sample-data.sh
Created February 22, 2023 14:36
Import WooCommerce Sample Data
# Install Importer
wp plugin install wordpress-importer --activate
# download the sample data
wget https://raw.githubusercontent.com/woocommerce/woocommerce/trunk/plugins/woocommerce/sample-data/sample_products.xml
# import the data
wp import sample_products.xml --authors=create
@thetwopct
thetwopct / wordpress-test-data-import.sh
Last active February 22, 2023 14:08
Import Theme Unit Test Data in to WordPress
#!/usr/bin/env bash
set -e
# Activate WP Importer plugin.
wp plugin install wordpress-importer --activate
# Don't know why, but failed importing directly.
wget https://raw.githubusercontent.com/WPTRT/theme-unit-test/master/themeunittestdata.wordpress.xml
# Import
wp import themeunittestdata.wordpress.xml --authors=create
@thetwopct
thetwopct / Toggle (Inspired by Apple) for Tax Toggle for WooCommerce
Created February 21, 2023 08:08
iOS-style Toggle for Tax Toggle for WooCommerce
This is a modification for Tax Toggle for WooCommerce (see https://www.taxtoggle.com?ref=gist)
It creates a iOS-style "toggle" button which can be inserted in your theme showing status of the tax toggle - either inclusive or exclusive or any other wording you wish to use.
How to use:
1. Go to WP Admin > WooCommerce > Settings > Tax and turn off the floating tax toggle.
2. Add the custom CSS to your theme.
3. Add the custom Tax Toggle to your theme (i.e. in the header.php file). You can change the wording (Excludes Tax / Includes Tax) to anything you want to describe the on/off tax function.
4. You can customise the toggle formatting with the simple CSS variables specified.
@thetwopct
thetwopct / .wp-env.json
Created February 17, 2023 04:14
Theme Review wordpress@env setup
{
"$schema": "https://raw.githubusercontent.com/WordPress/gutenberg/17c1465fa82a325b5e99a8a010e63b72c5c612e9/schemas/json/.wp-env.json",
"core": null,
"plugins": [
"https://github.com/WPTT/theme-sniffer/releases/download/1.1.2/theme-sniffer.zip",
"https://downloads.wordpress.org/plugin/query-monitor.zip",
"https://downloads.wordpress.org/plugin/log-deprecated-notices.zip",
"https://downloads.wordpress.org/plugin/theme-check.zip"
],
"themes": [
@thetwopct
thetwopct / myphpcs
Created January 19, 2023 08:39
squizlabs / PHP_CodeSniffer (phpcs) inside Docker in VS Code
#!/usr/bin/env bash
# Place this file in your Docker apps vendor/bin.
# Use VS Code plugin - PHP Sniffer & Beautifier by Samuel Hilson
# Set executablePath for PHPCS to be ./vendor/bin/myphpcs
# If you also want PHPCBF, duplicate this file, change any references of phpcs to phpcbf and add the CBF executable path.
set -eo pipefail
main_exec() {
@thetwopct
thetwopct / Simple on and off inline button for Tax Toggle.md
Last active January 14, 2023 08:40
Simple on and off inline button for Tax Toggle for WooCommerce

This is a modification for Tax Toggle for WooCommerce (see https://www.taxtoggle.com?ref=gist)

It creates a simple inline button in your theme showing status of the tax toggle - either inclusive or exclusive.

How to use:

  1. Go to WP Admin > WooCommerce > Settings > Tax and turn off the floating tax toggle.
  2. Add the custom CSS to your theme
  3. Add the custom Tax Toggle to your theme (i.e. in the header.php file). You can change the wording (Excludes Tax / Includes Tax) to anything you want to describe the on/off tax function.
@thetwopct
thetwopct / functions.php
Last active January 8, 2023 05:43
Customisation of Tax Toggle for WooCommerce for compatibility with 99w Rentals Plugin
<?php
/**
* Customisation of Tax Toggle for WooCommerce for compatibility with 99w Rentals Plugin
*
* Based on Tax Toggle for WooCommerce 1.3.6
*
* Plugin: https://1.envato.market/taxtoggle
*
* @param string $price_display_override Rental price.
@thetwopct
thetwopct / functions.php
Last active January 8, 2023 05:41
Deactivate Tax Toggle on some pages / meeting conditions.
<?php
/**
* Remove Tax inc/exc toggle code on some pages.
*
* Based on Tax Toggle for WooCommerce 1.3.6
*
* Plugin: https://1.envato.market/taxtoggle
*/
function woo_tax_toggle_remove_tax_on_some_pages(){