Skip to content

Instantly share code, notes, and snippets.

View remove_max_srcset_image_width.php
// Remove max_srcset_image_width.
function remove_max_srcset_image_width( $max_width ) {
return false;
}
add_filter( 'max_srcset_image_width', 'remove_max_srcset_image_width' );
@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;
@joemcgill
joemcgill / ricg-merge-notes.md
Created Dec 10, 2015
Random notes while thinking about the RICG merge into 4.4
View ricg-merge-notes.md

WP RICG Images merge notes

  • Consider merging get_image_tag() and wp_get_attachment_image().
    • Nah, bad idea. While get_image_tag() is only used in the media editor, it probably makes sense to keep the image generation on the back end and front end separated because of how people are likely filtering display.
  • Add an event listener to the editor if we can't do a content filter.
    • Look into adding needed metadata directly to wp.media to avoid the ajax request
  • Add caching to attachment_url_to_postid to speed up multiple requests.
  • Add smart ways to filter sizes globally w/o inducing another wp_get_attachment_image() call.
@joemcgill
joemcgill / wcus2015-notes.md
Created Dec 10, 2015
WordCamp US 2015 Notes
View wcus2015-notes.md

Tolman and Jorbin

  • list functions assign variables in reverse order in PHP7
  • HTTP/2
    • makes things faster by managing latency
    • introduces multiplexing in single TCP connections
    • #core-http on slack (working group)
  • CSS4
    • CSS color() function coming soon
    • varables in CSS
@joemcgill
joemcgill / no_responsive_image_feeds.php
Created Dec 3, 2015
Remove responsive images from feeds.
View no_responsive_image_feeds.php
function no_responsive_image_feeds() {
add_filter( 'max_srcset_image_width', function() {
return 1;
} );
}
add_action('rss2_head', 'no_responsive_image_feeds' );
add_action('atom_head', 'no_responsive_image_feeds' );
add_action('rss_head', 'no_responsive_image_feeds' );
@joemcgill
joemcgill / gist:89629cd4ac3cd975db89
Created Feb 21, 2015
A WordPress filter to avoid widows in your titles
View gist:89629cd4ac3cd975db89
<?php
/**
* A WordPress filter to avoid widows in your titles
*/
function avoid_title_widows( $title ) {
// Find the last space.
$last_space = strrpos($title, ' ');
// Replace it with a non-breaking space.
if ( $last_space ) {
View gist:1daee0e0819eea4ff5e7
/* Overrides the database for development URLs */
define('WP_SITEURL', 'http://my.domain.dev');
define('WP_HOME', 'http://my.domain.dev');
View gist:88791c562d9f8614a962
{
"bold_folder_labels": true,
"color_scheme": "Packages/User/base16-ocean.dark (SL).tmTheme",
"detect_slow_plugins": false,
"folder_exclude_patterns":
[
".git",
".sass-cache",
"bower_components"
],
@joemcgill
joemcgill / widow_buster.php
Created Sep 3, 2014
Wordpress Widow Busting Function
View widow_buster.php
<?php
/**
* Avoid widows in text by replacing the final space in each paragraph with a &nbsp;
*
* Inspired by David Walsh (http://davidwalsh.name/word-wrap-mootools-php)
*
* @param string $content Content passed into the filter
* @return string the filtered content
*/
function wustl_widow_buster ($content) {
@joemcgill
joemcgill / svgTest.js
Last active Aug 29, 2015
SVG Test w/o Modernizr
View svgTest.js
// SVG Test
(function () {
function supportsSVG() {
return !!document.createElementNS && !! document.createElementNS('http://www.w3.org/2000/svg', 'svg').createSVGRect;
}
if (!supportsSVG()) {
document.documentElement.className += ' no-svg';
// optional .png fallback for .svg files inlined as <img> elements
$("img[src$='.svg']").attr("src", function() {
return $(this).attr('src').replace('.svg', '.png');