Skip to content

Instantly share code, notes, and snippets.

View dkjensen's full-sized avatar
🏠
Working from home

David Jensen dkjensen

🏠
Working from home
View GitHub Profile
@dkjensen
dkjensen / functions.php
Created August 19, 2024 10:11
Preload WordPress theme.json custom fonts
<?php
/**
* Preload fonts.
*
* @return void
*/
function preload_fonts() {
$fonts = \WP_Font_Face_Resolver::get_fonts_from_theme_json();
@dkjensen
dkjensen / functions.php
Created June 20, 2024 20:55
Prevent hidden WooCommerce products from showing search results / prevent purchase
<?php
/**
* Add a noindex, follow robots meta tag to hidden products.
*
* @param string $robots The robots meta tag.
* @return string
*/
add_filter(
'wpseo_robots',
function ( $robots ) {
@dkjensen
dkjensen / force-two-factor.php
Created June 5, 2024 14:22
Enforce Two Factor for Administrators on WordPress
<?php
/**
* Plugin Name: Force Two Factor
* Description: Force Two Factor Authentication for some users.
* Requires at least: 6.0.2
* Requires PHP: 7.0
* Version: 0.0.0-development
* Author: CloudCatch LLC
* Author URI: https://cloudcatch.io
* License: GPL v2 or later
@dkjensen
dkjensen / blog-post.php
Created February 7, 2024 21:06
Sample WP Block Template Part
<?php
/**
* Template Part: Blog
*
* @package CloudCatch\Sample
*/
use function CloudCatch\Sample\get_post_icon;
$sample_blog_categories = wp_get_post_terms( get_the_ID(), 'category', array( 'fields' => 'names' ) );
@dkjensen
dkjensen / README.md
Last active June 18, 2024 16:02
WordPress Query Block as Splide Carousel

Instructions

  1. Add your query block, and give it a class of is-style-carousel.
  2. Add the code from block-editor.php somewhere such as your child theme functions.php file.
  3. Configure Splide options in the query_carousel_block_init() function.
@dkjensen
dkjensen / .lando.yml
Created October 30, 2023 19:48
Lando + XDebug + VSCode + WordPress
name: sandbox.local
recipe: wordpress
config:
php: 8.2
webroot: www
services:
database:
type: mariadb
appserver:
xdebug: true
@dkjensen
dkjensen / windows-wsl2-docker-lando-php-xdebug.md
Created June 18, 2023 18:34 — forked from rockschtar/windows-wsl2-docker-lando-php-xdebug.md
Windows 10/11 + WSL2 + Docker + Lando + PHP XDebug (PHPStorm, IntelliJ & Visual Studio Code (vscode))
  1. Install WSL
  2. Install your preferred WSL Linux Distro vom Microsoft Store. In my case I used Ubuntu 20.04.
  3. Install Docker for Windows
  4. Enable Docker WSL2 Integration image
  5. Install Lando inside WSL
wget https://github.com/lando/lando/releases/download/v3.6.0/lando-x64-v3.6.0.deb
dpkg -i --ignore-depends=docker-ce lando-x64-v3.6.0.deb
@dkjensen
dkjensen / filters.php
Last active October 31, 2024 22:27
WordPress Gutenberg Query Loop View More AJAX
<?php
/**
* Add data attributes to the query block to describe the block query.
*
* @param string $block_content Default query content.
* @param array $block Parsed block.
* @return string
*/
function query_render_block( $block_content, $block ) {
global $wp_query;
@dkjensen
dkjensen / osa-wave-r1.js
Created October 13, 2021 05:57
OSA Wave
"use strict";
var waves = document.querySelectorAll('[data-wave]');
var devicePixelRatio = window.devicePixelRatio || 1;
waves.forEach(function (wave) {
var fillColor = wave.getAttribute('data-fill') || '#f0f';
var clipDirection = wave.getAttribute('data-clip-direction') || 'top';
var containerWrapper = document.createElement('div');
containerWrapper.classList = 'containerWrapper';
var container = document.createElement('div');
@dkjensen
dkjensen / cart-table.php
Created July 21, 2020 22:28
Display SKU on WC Cart PDF table
<?php
/**
* WC Cart PDF template
*
* @package wc-cart-pdf
*/
/**
* Before template hook
*