Skip to content

Instantly share code, notes, and snippets.

View michaelschofield's full-sized avatar

Michael Schofield michaelschofield

View GitHub Profile
@michaelschofield
michaelschofield / wp_welcome_panel.php
Last active January 2, 2016 06:19
A welcome screen in the WordPress dashboard, but not using the actual welcome_panel hook because even customizing that will show only to site admins. Instead, this creates an admin notice and uses the welcome panel markup.
/* ==================
* Custom Welcome Panel
*/ // This is a custom welcome panel, sort of. The
// correct way of updating the welcome panel content
// is still only visible to users that can edit_theme_options.
// This takes the welcome-panel styles and adds it as an admin_notice.
function ms_welcome_panel() {
$screen = get_current_screen();
@michaelschofield
michaelschofield / LibTechGender_Fetch_Links_WP.php
Created January 19, 2014 22:47
An example of what the WP_Query() might look like to fetch all posts with the "LibTechGender" category that only have the "Link" post format.

The Sherman Library took the unique opportunity to build a public library website where there wasn’t one before. A fresh start, no baggage, with plenty of time to talk, plan, design, develop, make mistakes, get delayed, and user-test. This is the narrative of the entire process – the whole shebang: answering why the design committee opted to build a mobile-first, responsive, and flat website, the data they used to convince stakeholders to ditch the carousel, the techniques and pains behind development, content strategy, and seeing the website launch. Attendees have a unique look into the workflow of another library, the user-experience research and best practices that drove our decision-making. In short: we made the font huge, stopped supporting old Internet Explorers, took all the tabs off the search box, and embraced the white space. This is why.

@michaelschofield
michaelschofield / getQueryParameters.js
Created February 21, 2014 21:25
Returns the address bar query string as a key/value object.
/*
* jquery.getQueryParameters.js
* Copyright (c) 2014 Nicholas Ortenzio
* The MIT License (MIT)
*
*/
jQuery.extend({
getQueryParameters : function(str) {
@michaelschofield
michaelschofield / ordinals.js
Created February 21, 2014 21:29
Simple one-liner to painlessly return ordinals.
function nth(o){return o+([‘st’,’nd’,’rd’][(o+’’).match(/1?\d\b/)-1]||’th’)}
@michaelschofield
michaelschofield / semantic-directory.html
Last active August 29, 2015 13:57
Trying to markup the most semantic directory ever. Inspired by cool semantic things being done by Jason Clark and Scott Young.
# Have to get creative with Schema though. I'm actively finagling. DTs cannot contain any block level elements, but DDs can.
<dl vocab="http://schema.org/" typeof="Person">
<dt property="name">Sandra Fiegi</dt>
<dd>
<img property="image" src="example.jpg" alt="A photo of Sandra Fiegi">
</dd>
@michaelschofield
michaelschofield / parallel.js
Created May 2, 2014 13:24
Multiple AJAX and JSON Requests, One Callback
// From David Waslh: http://davidwalsh.name/jquery-ajax-callback
$.when(
$.getScript('/media/js/wiki-min.js?build=21eb633'),
$.getJSON('https://developer.mozilla.org/en-US/demos/feeds/json/featured/')
).then(function(a, b) { // or ".done"
// Yay, stuff loaded and now we can do something!
});
// There are probably more legit ways of doing this,
// but for my sparse use I sometimes use this.
// IE8 ployfill for GetComputed Style (for Responsive Script below)
if (!window.getComputedStyle) {
window.getComputedStyle = function(el, pseudo) {
this.el = el;
this.getPropertyValue = function(prop) {
var re = /(\-([a-z]){1})/g;
if (prop == 'float') prop = 'styleFloat';
(function() {
var CSSCriticalPath = function(w, d, opts) {
var opt = opts || {};
var css = {};
var pushCSS = function(r) {
if(!!css[r.selectorText] === false) css[r.selectorText] = {};
var styles = r.style.cssText.split(/;(?![A-Za-z0-9])/);
for(var i = 0; i < styles.length; i++) {
if(!!styles[i] === false) continue;
var pair = styles[i].split(": ");
@michaelschofield
michaelschofield / micromanage-assets.php
Created July 17, 2014 21:39
A little WordPress function for micromanaging what, where, and when scripts and styles load.
// Deregister all the things
add_action( 'wp_print_scripts', 'libux_deregister_scripts', 100 );
function libux_deregister_scripts() {
// Ditch jQuery - except on one page that requires it,
// but load that with a CDN.
wp_deregister_script( 'jquery' );
if ( is_page( 'something' ) ) {