Skip to content

Instantly share code, notes, and snippets.

View menslow's full-sized avatar

Michael Enslow menslow

View GitHub Profile
@menslow
menslow / lazyload-get-the-post-thumbnail.php
Last active November 13, 2017 13:10
Rewrite of the WordPress "get_the_post_thumbnail" for compatibility with jQuery LazyLoad plugin
<php
// Rewrite of "get_the_post_thumbnail" for compatibility with jQuery LazyLoad plugin
function my_get_the_post_lazyload_thumbnail( $post_id = false, $size = 'full' ) {
if ( $post_id ) {
// Get the id of the attachment
$attachment_id = get_post_thumbnail_id( $post_id );
if ( $attachment_id ) {
$src = wp_get_attachment_image_src( $attachment_id, $size );
if ($src) {
$img = get_the_post_thumbnail( $post_id, $size, array(
@menslow
menslow / genesis-favicon-filter.php
Last active August 29, 2015 14:07
Genesis Filter for customizing favicons and Apple Touch icons
<?php
// Filter for Genesis Parent theme to Customize favicon and add Apple Touch Icons
add_filter( 'genesis_pre_load_favicon', 'my_pre_load_favicon');
function my_pre_load_favicon() {
echo '<link rel="shortcut icon" href="' . get_stylesheet_directory_uri() . '/lib/images/favicon.ico">'.PHP_EOL
.'<link rel="apple-touch-icon" href="touch-icon-iphone.png">'.PHP_EOL
.'<link rel="apple-touch-icon" sizes="76x76" href="' . get_stylesheet_directory_uri() . '/lib/images/logo-76.png">'.PHP_EOL
.'<link rel="apple-touch-icon" sizes="120x120" href="' . get_stylesheet_directory_uri() . '/lib/images/logo-76@2x.png">'.PHP_EOL
.'<link rel="apple-touch-icon" sizes="152x152" href="' . get_stylesheet_directory_uri() . '/lib/images/logo-76@2x.png">';
}
@menslow
menslow / middleman-partials.erb
Last active August 29, 2015 14:03
Using Middleman partials for organizing your pattern library.
<!--
Here's our Header "container" partial
_header.erb
-->
<header class="header">
<section class="tool-bar row">
<div class="large-12 columns">
<%= partial "shared/_logo" %>
<div class="connect">
@menslow
menslow / middleman-config.rb
Created June 27, 2014 18:31
Middleman Configuration for Development and Production
# Turn on Livereload for development to reload your browser atomatically when you save changes to source files.
configure :development do
activate :livereload
end
# Turn on CSS and JavaScript minification for your production build files.
configure :build do
activate :minify_css
activate :minify_javascript
end
@menslow
menslow / namespace-pattern.js
Created June 27, 2014 18:24
JavaScript Namespace Pattern
var CS = (function() {
var $ = jQuery;
return {
init: function() {
this.setFoundation();
this.setJS();
this.setMenuEvents();
@menslow
menslow / _text-size-adjust.scss
Last active February 26, 2017 15:15
Sass mixin for text-size-adjust
// text-size-adjust
//------------------------------------------------
//
// Values: none (default), auto, 100%
//
// Reference:
// https://developer.mozilla.org/en-US/docs/Web/CSS/text-size-adjust
//
@menslow
menslow / gist:5873095
Created June 27, 2013 00:41
TexExpander Snippet for dropping the default WordPress tables (without dropping the whole database). Complete with field for adding your table prefix.
DROP TABLE %filltext:name=prefix:default=wp:width=6%_commentmeta;
DROP TABLE %filltext:name=prefix:default=wp:width=6%_comments;
DROP TABLE %filltext:name=prefix:default=wp:width=6%_links;
DROP TABLE %filltext:name=prefix:default=wp:width=6%_options;
DROP TABLE %filltext:name=prefix:default=wp:width=6%_postmeta;
DROP TABLE %filltext:name=prefix:default=wp:width=6%_posts;
DROP TABLE %filltext:name=prefix:default=wp:width=6%_term_relationships;
DROP TABLE %filltext:name=prefix:default=wp:width=6%_term_taxonomy;
DROP TABLE %filltext:name=prefix:default=wp:width=6%_terms;
DROP TABLE %filltext:name=prefix:default=wp:width=6%_usermeta;
@menslow
menslow / gist:5511828
Created May 3, 2013 17:42
CMS driven 404 page for Genesis Framework
<?php
/**
* Handles display of 404 page.
*
* This file requires the creation of a page with the slug 'page-not-found'
*/
function jb_page_404(){
genesis_custom_loop( array('pagename' => 'page-not-found', 'posts_per_page' => 1 ) );
}
@menslow
menslow / PHP truncate functions
Created April 16, 2012 20:14
PHP: Couple of yummy truncate functions.
/**
* truncate_words function to truncate a string of words to a specified number of words
* @param string $str The text string to split
* @param integer $words The number of words to extract. Defaults to 15
*/
function truncate_words( $str, $words = 15 )
{
$arr = preg_split( '/[\s]+/', $str, $words+1 );
$arr = array_slice( $arr, 0, $words );
return join( ' ', $arr ) . '&hellip;';
@menslow
menslow / WordPress Show Admin Bar
Created April 16, 2012 18:20
WordPress: Add filter to control which users see the admin bar.
/**
* mm_show_admin_bar function.
* Filter to control which users see the admin bar.
* @access public
* @return false or true if user is admin.
*/
function mm_show_admin_bar() {
if (current_user_can('administrator')) {
return true;
} else {