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 / wp-alignment-classes.css
Created November 24, 2017 15:52
New WordPress alignment classes introduced by Gutenberg
/* -------------------------------------------------------------
# Variables
------------------------------------------------------------- */
$site_maxwidth: 72rem; // Maximum width the entire site should not exceed
$site_maxwidth-text: 40rem; // Maximum width the main content text should not exceed
$spacing_horizontal: 1rem; // General horizontal padding
/* -------------------------------------------------------------
# General Styles
@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-lazyload-lcp-fix.php
Last active March 11, 2024 22:13
Prototype plugin used for lazy-load LCP analysis in WordPress
<?php
/**
* Plugin initialization file
*
* @wordpress-plugin
* Plugin Name: Lazyload LCP Fix
* Plugin URI: https://gist.github.com/felixarntz
* Description: Omits the first content image from being lazy-loaded, to improve LCP performance.
* Version: 1.0.0
* Author: Felix Arntz, Google
@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 / README.md
Last active February 23, 2024 11:04
Mini WordPress core server performance test suite

Mini WordPress core server performance test suite

Purpose

This quick "mini test suite" allows you to easily collect server-side performance metrics for WordPress core development. It does so by utilizing the Server-Timing header.

Usage

  1. Paste the code from main.php into pretty much anywhere in WordPress core, e.g. into wp-includes/default-filters.php.
  2. Use code like the one in example.com around any code or a specific function that you want to record metrics for.
@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-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