Skip to content

Instantly share code, notes, and snippets.

@joemcgill
joemcgill / textbg.css
Created Nov 5, 2012
Inline Text Background (CSS only)
View textbg.css
/*
* 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;
@joemcgill
joemcgill / ssl_srcset.php
Created Dec 11, 2015
Force WordPress `srcset` to HTTPS
View ssl_srcset.php
/*
* 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;
View force-gutenberg-fullscreen.md

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 Jul 20, 2020
Fix Instagram embeds with Jetpack shortcodes module
View plugin.php
<?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 Mar 4, 2020
Remove filters added from class instances on a specific hook.
View Remove Class Filters Example
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 Dec 11, 2018
A11y test example for axe-puppeteer.
View axe-report.js
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)
}
@joemcgill
joemcgill / attachment_fields_to_edit_demo.php
Last active Nov 9, 2018
Attachment Fields to Edit Demo
View attachment_fields_to_edit_demo.php
<?php
add_filter( 'attachment_fields_to_edit', 'attachment_location_field', 10, 2 );
add_filter( 'attachment_fields_to_save', 'save_location_field', null, 2 );
function attachment_location_field( $form_fields, $post ) {
$field_value = get_post_meta( $post->ID, 'location', true );
$form_fields['location'] = array(
@joemcgill
joemcgill / show_img_vars.php
Last active Oct 14, 2016
A poor man's var_dump for the image_send_to_editor() filter in Wordpress. Throw this in your functions.php file and add an image to your post to see what get's passed. Filter it however you want to return the image however you want.
View show_img_vars.php
<?php
function show_img_vars($html, $id, $caption, $title, $align, $url, $size, $alt) {
// round up all the variables that get passed so we can test them
$vars = "html = $html\n";
$vars .= "id = $id\n";
$vars .= "caption = $caption\n";
$vars .= "title = $title\n"; // this will end up blank no matter what
$vars .= "align = $align\n";
$vars .= "url = $url\n";
@joemcgill
joemcgill / WP Fix Image Margins
Last active Oct 14, 2016
Removes the silly 10px margin from caption based images in WP (H/T Justin Adie)
View WP Fix Image Margins
/**
* Description: removes the silly 10px margin from caption based images
* Author: Justin Adie
* Version: 0.1.0
* Author URI: http://rathercurious.net
*/
class fixImageMargins{
public $xs = 0; //change this to change the amount of extra spacing
@joemcgill
joemcgill / parse_youtube_url
Created Sep 16, 2013
A handy javascript function for parsing YouTube urls and returning just the video URI (adapted from: http://stackoverflow.com/posts/9102270/revisions).
View parse_youtube_url
function parse_youtube_url(url) {
var regExp = /^.*(youtu.be\/|v\/|u\/\w\/|embed\/|watch\?v=v=|\&v=)([^#\&\?]*).*/;
var match = url.match(regExp);
if (match&&match[2].length==11){
return match[2];
}else{
//error
}
}