Skip to content

Instantly share code, notes, and snippets.

View plasticmind's full-sized avatar

Jesse Gardner plasticmind

View GitHub Profile
@plasticmind
plasticmind / navigate-all
Created February 13, 2014 18:53
Next/Previous: Include multiple post types
/* = Adjust next/previous links to include multiple post types */
/*
* Replacement for get_adjacent_post()
*
* This supports only the custom post types you identify and does not
* look at categories anymore. This allows you to go from one custom post type
* to another which was not possible with the default get_adjacent_post().
* Orig: wp-includes/link-template.php
*
@plasticmind
plasticmind / gist:9260407
Created February 27, 2014 21:53
UIWebView links open in Safari if the URL doesn't match a certain pattern
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType {
if ( navigationType == UIWebViewNavigationTypeLinkClicked ) {
NSString *urlString = request.URL.absoluteString;
// Set the pattern to search the request URL for
NSRange range = [urlString rangeOfString:@"mobile.example.com"];
if (range.location != NSNotFound) {
NSLog(@"%s", "This link matches the pattern and will be loaded in-app within the UIWebView.");
return YES;
} else {
NSLog(@"%s", "This link does NOT match the pattern and will be loaded in Safari.");
<?php
// change to repo directory, run a git pull and echo the output
echo shell_exec("cd /your/repo/path/here && git pull");
die("done " . mktime());
// == Create a simple hash based on a file checksum
function sr_version_hash($file) {
if(!$file) return false;
$full_path = get_template_directory() . $file;
return hash_file('CRC32',$full_path);
}
@plasticmind
plasticmind / gist:14e04ebfa734b13e720f
Created November 19, 2014 17:07
Adjusted Bounce Rate for Google Analytics
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-XXXXXXXX']);
_gaq.push(['_trackPageview']);
setTimeout("_gaq.push(['_trackEvent', '15_seconds', 'read'])",15000);
setTimeout("_gaq.push(['_trackEvent', '30_seconds', 'read'])",30000);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
@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) {