Skip to content

Instantly share code, notes, and snippets.

@joemcgill
joemcgill / ssl_srcset.php
Created December 11, 2015 03:23
Force WordPress `srcset` to HTTPS
/*
* Force URLs in srcset attributes into HTTPS scheme.
* This is particularly useful when you're running a Flexible SSL frontend like Cloudflare
*/
function ssl_srcset( $sources ) {
foreach ( $sources as &$source ) {
$source['url'] = set_url_scheme( $source['url'], 'https' );
}
return $sources;
@joemcgill
joemcgill / experimental-image-sizes.php
Last active October 10, 2024 18:10
Experimental: image sizes calculation during block rendering
<?php
/**
* Plugin Name: Experimental Image Sizes
* Description: MU plugin for experiemnting with `sizes` calulations.
* Version: 0.1.0
*/
add_filter( 'render_block_core/image', 'wpp_add_image_block_sizes', 10, 3 );
/**
@joemcgill
joemcgill / WP Helpers.md
Last active September 13, 2024 19:28
WP Dev: Custom Bash Functions

WP Helpers

These are a few small utility functions that I use when working on WordPress.

Installation

These can be copied directly into your ~/.bashrc or ~/.zshrc file (whichever is applicable) or put them in a file that is added to your path. I use Oh My Zsh on my sytem, and have this file saved to ~/.oh-my-zsh/custom/plugins/wp-dev/wp-dev.plugin.zsh and have added wp-dev to the list of plugins in my .zshrc file.

What's included

gh-patch

Quickly apply a PR from https://github.com/WordPress/wordpress-develop as a patch to an SVN checkout of WordPress. This is a huge time saver when I'm committing changes to WordPress.

@joemcgill
joemcgill / README.md
Last active April 15, 2024 08:35
WPP Better Image Sizes is a proof of concept WordPress plugin that provides a better calculation for the default sizes attribute for images.

WPP Better Image Sizes

This is a WordPress Plugin that improves the default sizes attribute calculation for images.

Description

WPP Better Image Sizes is a WordPress plugin that provides a better calculation for the default sizes attribute for images. This plugin is designed to enhance the performance and responsiveness of your WordPress site.

Installation

@joemcgill
joemcgill / plugin.php
Last active November 24, 2023 08:53
WP 6.4 Theme Path Fixer
<?php
/*
* Plugin Name: WP 6.4 Theme path fixer
* Plugin URI: https://gist.github.com/joemcgill/dd569c287013ad545f41495f93d7a27e
* Description: Fix problems with theme directory memoization in WP 6.4.
* Version: 1.0
* Requires at least: 6.4
* Author: Joe McGill
* Author URI: https://joemcgill.net
* License: GPL v2 or later
@joemcgill
joemcgill / textbg.css
Created November 5, 2012 22:10
Inline Text Background (CSS only)
/*
* Class for defining text with background on text only and not the whole block.
* May require definition of html element (i.e. p.textbg) in order to make line-height
* and font-size work.
*/
.textbg {
padding:5px 0; /* top and bottom padding */
color:#fff;
font-size: 24px;

Force Gutenberg to Fullscreen Mode

This is an example snippet for forcing the Gutenberg editor into full screen mode in anticipation of the change coming to WordPress 5.4.

@joemcgill
joemcgill / plugin.php
Created July 20, 2020 19:06
Fix Instagram embeds with Jetpack shortcodes module
<?php
// Disable Jetpack's instagram shortcode since it breaks oEmbed functionality.
add_filter( 'jetpack_shortcodes_to_include', function ( $shortcodes ) {
unset( $shortcodes['instagram'] );
return $shortcodes;
}, 99 );
// Add a simple shortcode wrapper for the embed functionality to support the shortcode format.
@joemcgill
joemcgill / Remove Class Filters Example
Last active March 4, 2020 01:43
Remove filters added from class instances on a specific hook.
class Test_Class {
public function __construct() {
add_filter( 'pre_get_posts', [$this, 'test_callback'] );
}
public function test_callback() {
wp_die( 'Hooked up.' );
}
}
@joemcgill
joemcgill / axe-report.js
Created December 11, 2018 18:12
A11y test example for axe-puppeteer.
const colors = require('colors');
const link = colors.underline.blue;
const error = colors.red.bold;
function selectorToString(selectors, separator) {
separator = separator || ' '
return selectors
.reduce((prev, curr) => prev.concat(curr), [])
.join(separator)
}