Skip to content

Instantly share code, notes, and snippets.

@lukecav
lukecav / Links
Last active June 14, 2021 02:05
Speed Up Your WordPress Site with These 3 Advanced Techniques Workshop - WordSesh 2021
@myogeshchavan97
myogeshchavan97 / trap_focus.js
Last active November 26, 2022 08:46
Code for trapping focus inside modal
// add all the elements inside modal which you want to make focusable
const focusableElements =
'button, [href], input, select, textarea, [tabindex]:not([tabindex="-1"])';
const modal = document.querySelector('#exampleModal'); // select the modal by it's id
const firstFocusableElement = modal.querySelectorAll(focusableElements)[0]; // get first element to be focused inside modal
const focusableContent = modal.querySelectorAll(focusableElements);
const lastFocusableElement = focusableContent[focusableContent.length - 1]; // get last element to be focused inside modal
<?php
function lean_column_props( string $block_content, array $block ) : string {
$width = $block['attrs']['width'] ?? false;
$class_pos = strpos( $block_content, 'wp-block-column' );
$column_class = 'w-full px-1';
$column_class .= ( $width ? ' md:w-' . round( 12 * $width / 100 ) . '/12 ' : '' );
// Add to the existing classes if there are some already.
$class_pos = strpos( $block_content, 'class="' );
@jan-koch
jan-koch / remove-woo-scripts.php
Created February 28, 2020 09:14
Remove WooCommerce related resources except on WooCommerce-based pages (products, cart, checkout, etc). Use on a testing environment before pasting this into your live website!
/**
* This code snippet removes JavaScript and CSS files loaded from WooCommerce if they are not necessary.
*
* Please test this on a staging copy of your website before putting this into the functions.php of your live website.
*/
add_action( 'wp_enqueue_scripts', 'my_remove_woo_assets', 99 );
function my_remove_woo_assets() {
if ( function_exists( 'is_woocommerce' ) ) { // Check if Woo is installed.
if ( ! is_woocommerce() && ! is_cart() && ! is_checkout() ) { // Only run on non-Woo pages.
// Remove unnecessary stylesheets.
@akella
akella / setup.md
Last active May 1, 2024 05:33
My Setup
@tarecord
tarecord / get_primary_taxonomy_term.php
Last active October 7, 2023 18:16
Returns the primary term for the chosen taxonomy set by Yoast SEO or the first term selected.
<?php
/**
* Returns the primary term for the chosen taxonomy set by Yoast SEO
* or the first term selected.
*
* @link https://www.tannerrecord.com/how-to-get-yoasts-primary-category/
* @param integer $post The post id.
* @param string $taxonomy The taxonomy to query. Defaults to category.
* @return array The term with keys of 'title', 'slug', and 'url'.
*/
@ericclemmons
ericclemmons / README.md
Created April 15, 2018 23:36
Hot take on Zach Silveira's Gutenblock Demo!
@zackify
zackify / docker-compose.yml
Created April 15, 2018 18:17
Quickstart gutenblock (docker-compose up and it will sync blocks folder)
version: '3.3'
services:
db:
image: mysql:latest
volumes:
- dbdata:/var/lib/mysql
restart: always
ports:
- "3306:3306"
@adriennetacke
adriennetacke / countdown.js
Last active September 1, 2022 04:18
Countdown timer in pure JavaScript
function countdown(endDate) {
let days, hours, minutes, seconds;
endDate = new Date(endDate).getTime();
if (isNaN(endDate)) {
return;
}
setInterval(calculate, 1000);
@jshakes
jshakes / sublime-wordpress-linting-setup.md
Last active September 14, 2018 03:52
Installing Wordpress PHP linting in SublimeText

Install phpcs with homebrew:

brew install php-code-sniffer

cd /usr/local/lib (or wherever you want to the code sniffer rules to live)

Clone the WP rules:

git clone -b master https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards.git wpcs