Skip to content

Instantly share code, notes, and snippets.

View plasticmind's full-sized avatar

Jesse Gardner plasticmind

View GitHub Profile
@plasticmind
plasticmind / gist:3823053
Created October 2, 2012 20:24
Inject class into $before_widget variable
// Let's inject a little class into our $before_widget variable
if( strpos($before_widget, 'class') === false ) { // It has no class... let's add it!
$before_widget = str_replace('>', ' class="custom-class-name">', $before_widget);
} else { // We have class... let's append it!
$before_widget = str_replace('class="', 'class="custom-class-name ', $before_widget);
}
// Register our _mobile query variable
add_filter('query_vars', 'sr_mobile_var');
function sr_mobile_var($public_query_vars) {
$public_query_vars[] = '_mobile';
return $public_query_vars;
}
// Catch all /m/ requests and rewrite them as mobile
add_rewrite_rule('^m/([^/]*)?','$matches[1]&_mobile','top');
@plasticmind
plasticmind / gist:4162908
Created November 28, 2012 18:02
Remove the second space after a period in WordPress posts
// See: http://www.jetmore.org/john/blog/2012/03/multiple-spaces-after-period-in-wordpress/
function gist_kill_double_space( $content ) {
if ( seems_utf8( $content ) ) {
$clean_content = preg_replace( '/[\p{Z}\s]{2,}/u', ' ', $content );
} else {
$clean_content = preg_replace( '/\s\s+/', ' ', $content );
}
return $clean_content;
}
add_filter( 'the_content', 'gist_kill_double_space' );
@plasticmind
plasticmind / gist:4277101
Created December 13, 2012 15:24
Remove unnecessary items from the admin bar
// Remove unnecessary items from the admin bar
function gist_custom_admin_bar_remove() {
global $wp_admin_bar;
$wp_admin_bar->remove_menu('wp-logo');
// $wp_admin_bar->remove_menu('comments');
$wp_admin_bar->remove_menu('new-media');
$wp_admin_bar->remove_menu('new-link');
$wp_admin_bar->remove_menu('new-user');
$wp_admin_bar->remove_menu('new-theme');
$wp_admin_bar->remove_menu('new-plugin');
@plasticmind
plasticmind / gist:4282236
Created December 14, 2012 02:51
Hash Cache
function my_load_meta() {
$script = '/js/script.js';
wp_enqueue_script( 'my-tools', get_template_directory_uri().$script, null, my_version_hash($script) );
$stylesheet = '/style.css';
wp_enqueue_style( 'my-style', get_template_directory_uri().$stylesheet, null, my_version_hash($stylesheet) );
}
add_action('wp_enqueue_scripts', 'my_load_meta');
// Create a hash of the file and pass it back for caching purposes
function my_version_hash($file) {
@plasticmind
plasticmind / gist:4337952
Created December 19, 2012 16:20
Adds a confirmation dialogue to the WordPress publish button.
/* = Add a "molly guard" to the publish button */
add_action( 'admin_print_footer_scripts', 'sr_publish_molly_guard' );
function sr_publish_molly_guard() {
echo <<<EOT
<script>
jQuery(document).ready(function($){
$('#publishing-action input[name="publish"]').click(function() {
if(confirm('Are you sure you want to publish this?')) {
return true;
@plasticmind
plasticmind / gist:4339164
Created December 19, 2012 18:31
Confuse and annoy your friends with CSS. Every 20 seconds, blur the screen for 2 seconds.
html {
-webkit-animation: annoy 20s ease alternate infinite;
}
@-webkit-keyframes annoy {
0% { -webkit-filter: blur(0px) }
90% { -webkit-filter: blur(0px) }
100% { -webkit-filter: blur(1px) }
}
@plasticmind
plasticmind / gist:5262783
Created March 28, 2013 12:34
Bookmarklet: Search this domain
javascript:(function(){ p=prompt('Search this domain for:',''); if(p){ document.location.href='http://www.google.com/search?q=site:'+document.location.href.split('/')[2]+' '+escape(p)} })();
@plasticmind
plasticmind / jquery.infinitescroll.sr.js
Created June 12, 2013 18:11
Behavior for Infinite Scroll jQuery plugin: infinite scrolling doesn't begin until after a manual trigger is clicked.
/*
--------------------------------
Infinite Scroll Behavior
Simply Recipes Mobile Style
: Infinite scroll waits for a one-time manual trigger
--------------------------------
by Jesse Gardner, http://plasticmind.com
*/
$.extend($.infinitescroll.prototype,{
@plasticmind
plasticmind / gist:6799419
Last active December 24, 2015 12:39
All apple-touch-icon permutations...
<!-- non-retina iPhone pre iOS 7 -->
<link rel="apple-touch-icon" href="apple-touch-icon-57x57.png" sizes="57x57">
<!-- non-retina iPad pre iOS 7 -->
<link rel="apple-touch-icon" href="apple-touch-icon-72x72.png" sizes="72x72">
<!-- non-retina iPad iOS 7 -->
<link rel="apple-touch-icon" href="apple-touch-icon-76x76.png" sizes="76x76">
<!-- retina iPhone pre iOS 7 -->
<link rel="apple-touch-icon" href="apple-touch-icon-114x114.png" sizes="114x114">
<!-- retina iPhone iOS 7 -->
<link rel="apple-touch-icon" href="apple-touch-icon-120x120.png" sizes="120x120">