Skip to content

Instantly share code, notes, and snippets.

View felixarntz's full-sized avatar

Felix Arntz felixarntz

View GitHub Profile
@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.
View prevent-jetpack-subscriptions-thickbox.php
<?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
View server-timing-output-buffer.php
<?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
View theme.json
{
"$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
View web-vitals-logger.php
<?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
View server-timing-extra.php
<?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
@felixarntz
felixarntz / README.md
Last active February 7, 2023 04:41
Mini WordPress core server performance test suite
View README.md

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 / perflab-server-timing-examples.php
Last active November 24, 2022 00:29
Some example use-cases for the Server Timing API in the Performance Lab plugin (see https://github.com/WordPress/performance/pull/553). A previous version for an older implementation of the API can be found at https://gist.github.com/felixarntz/c343a33242b6527ad3f446c8f7f4fec2.
View perflab-server-timing-examples.php
<?php
add_action(
'plugins_loaded',
function() {
// Utility function that returns a measuring callback for an action hook,
// which should be registered as a metric within the action as early as possible
// (see PHP_INT_MIN usage below).
$get_measure_action_callback = function( $action_hook ) {
return function( $metric ) use ( $action_hook ) {
$metric->measure_before();
@felixarntz
felixarntz / perflab-server-timing-examples.php
Last active October 31, 2022 23:14
Some example use-cases for the Server Timing API in the Performance Lab plugin (see https://github.com/WordPress/performance/pull/553). This example is outdated (see comment below)!
View perflab-server-timing-examples.php
<?php
add_action(
'perflab_server_timing_init',
function( $server_timing ) {
// Utility function that returns a measuring callback for an action hook.
$measure_action = function( $action ) {
return function ( $metric ) use ( $action ) {
$start_time = null;
// If action is already running, at least measure the remainder.
@felixarntz
felixarntz / wp-lazyload-lcp-fix.php
Last active July 16, 2021 18:55
Prototype plugin used for lazy-load LCP analysis in WordPress
View wp-lazyload-lcp-fix.php
<?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
View fix-site-kit-canonical-home-url-multilingual.php
<?php
/**
* Ensures Site Kit ignores contextual home URL path modifications added by certain multilingual plugins.
*
* @author Felix Arntz, Google
* @license Apache 2.0
* @copyright 2020 Google Inc.
*
* @wordpress-plugin
* Plugin Name: Fix Site Kit Canonical Home URL Multilingual