Skip to content

Instantly share code, notes, and snippets.

View felixarntz's full-sized avatar

Felix Arntz felixarntz

View GitHub Profile
@felixarntz
felixarntz / git-svn-up.sh
Created September 22, 2024 19:10
Bash script to manage WordPress git and svn checkouts in the same directory
#!/bin/bash
#
# This scripts updates Git and SVN repos checked out in the same directory.
#
# Pass a branch name like 4.6 as the sole argument to checkout that branch. Otherwise, trunk/trunk is checked out.
#
# Written by Weston Ruter (https://weston.ruter.net/)
cd $( git rev-parse --show-toplevel )
@felixarntz
felixarntz / functions.php
Created April 25, 2024 19:12
Allowing inline images in WordPress block themes to use `alignright` / `alignleft` classes (e.g. in Twenty Twenty-Three child theme)
<?php
/**
* Styles 'alignright' and 'alignleft' inline elements to appear within horizontal content width.
*/
function twentytwentythree_felixarntz_style_alignright_alignleft() {
$extra_css = 'body .is-layout-flow > :where(:not(.alignleft):not(.alignright):not(.alignfull)) > .alignright {';
$extra_css .= 'float: right;';
$extra_css .= 'margin-inline-start: 2em;';
$extra_css .= 'margin-inline-end: 0;';
@felixarntz
felixarntz / wp-server-timing-quick-hack-template.php
Created March 8, 2024 01:06
wp-server-timing-quick-hack-template.php (using Performance Lab Server-Timing API)
<?php
function my_func() {
global $some_metric_global;
if ( ! isset( $some_metric_global ) ) {
$some_metric_global = 0.0;
add_action(
'wp_footer',
function() {
@felixarntz
felixarntz / wp-total-compared-with-ttfb.sql
Created October 26, 2023 23:36
HTTP Archive query comparing Server-Timing `wp-total` (from Performance Lab plugin) with Time to First Byte
CREATE TEMPORARY FUNCTION GET_SERVER_TIMING_HEADER(headers ARRAY<STRUCT<name STRING, value STRING>>) RETURNS STRING AS (
IFNULL((
SELECT
value
FROM
UNNEST(headers) AS header
WHERE
LOWER(header.name) = 'server-timing'
LIMIT 1
), '')
@felixarntz
felixarntz / wp-64-beta1-benchmarks.md
Created October 3, 2023 00:13
Local results from running https://github.com/swissspidy/compare-wp-performance for WordPress 6.4 Beta 1

WP 6.4 Beta 1 Benchmarks

Compared to WP 6.3.1 via https://github.com/swissspidy/compare-wp-performance, based on running:

./run.sh latest https://wordpress.org/wordpress-6.4-beta1.zip

Overview

| Metric | Run 1 Before | Run 1 After | Run 1 Diff % | Run 1 Diff abs. | Run 2 Before | Run 2 After | Run 2 Diff % | Run 2 Diff abs. |

@felixarntz
felixarntz / prevent-jetpack-subscriptions-thickbox.php
Created September 27, 2023 04:08
Jetpack uselessly enqueues Thickbox JS (which itself enqueues jQuery!) when rendering the Subscriptions block, even though it doesn't even use Thickbox. I use this snippet on my own site to fix it.
<?php
/**
* Fix Jetpack Subscriptions block to not uselessly enqueue Thickbox, which in turn enqueues jQuery.
*/
function felixarntz_stop_jetpack_subscriptions_from_enqueuing_thickbox_without_any_usage() {
if ( wp_script_is( 'jetpack-block-subscriptions' ) && isset( wp_scripts()->registered['jetpack-block-subscriptions'] ) ) {
$script = wp_scripts()->registered['jetpack-block-subscriptions'];
$index = array_search( 'thickbox', $script->deps, true );
if ( false !== $index ) {
@felixarntz
felixarntz / server-timing-output-buffer.php
Last active March 10, 2023 21:22
Mini WordPress plugin that enables output buffering in the Server Timing API of the Performance Lab plugin (also see https://github.com/WordPress/performance/pull/553) to unlock a few additional metrics
<?php
/**
* Plugin Name: Server Timing Output Buffer
* Plugin URI: https://gist.github.com/felixarntz/9c3d7150c74082e69bb426393b68b12e
* Description: Enables output buffering in the Performance Lab plugin's Server Timing API.
* Requires at least: 6.1
* Requires PHP: 5.6
* Version: 0.1.0
* Author: Felix Arntz
* Author URI: https://felix-arntz.me
@felixarntz
felixarntz / theme.json
Created March 4, 2023 19:55
My Twenty Twenty-Three child theme's `theme.json` for https://felix-arntz.me
{
"$schema": "https://schemas.wp.org/trunk/theme.json",
"version": 2,
"settings": {
"color": {
"palette": [
{
"color": "#ffffff",
"name": "Base",
"slug": "base"
@felixarntz
felixarntz / web-vitals-logger.php
Last active February 16, 2023 22:55
Mini WordPress plugin that uses https://github.com/GoogleChrome/web-vitals to log Core Web Vitals and other key client metrics to the browser console
<?php
/**
* Plugin Name: Web Vitals Logger
* Plugin URI: https://gist.github.com/felixarntz/112c5dcb72ca3af86557550979a5e9dd
* Description: Logs Core Web Vitals and other useful client-side metrics in the browser console.
* Requires at least: 6.1
* Requires PHP: 5.6
* Version: 0.1.0
* Author: Felix Arntz
* Author URI: https://felix-arntz.me
@felixarntz
felixarntz / server-timing-extra.php
Last active August 9, 2023 05:23
Mini WordPress plugin that uses the Server Timing API of the Performance Lab plugin (also see https://github.com/WordPress/performance/pull/553) to capture additional metrics
<?php
/**
* Plugin Name: Server Timing Extra
* Plugin URI: https://gist.github.com/felixarntz/63c05392dbf7d51cc7f8f4a424b1ff39
* Description: Exposes additional Server-Timing metrics using the Performance Lab plugin's Server Timing API.
* Requires at least: 6.1
* Requires PHP: 5.6
* Version: 0.1.0
* Author: Felix Arntz
* Author URI: https://felix-arntz.me