Skip to content

Instantly share code, notes, and snippets.

@delputnam
delputnam / wp-bootstrap-navbar-searchform.php
Created May 9, 2013 16:10
A Bootstrap navbar-compatible search form for use with Wordpress.
<form class="navbar-search pull-right" id="searchform" action="<?php echo home_url( '/' ); ?>">
<input type="text" class="search-query" placeholder="Search" value="" name="s" id="s">
</form>
@delputnam
delputnam / windowHistorySupported.js
Created May 10, 2013 12:01
Determine if a browser supports window.history.pushState.
function windowHistorySupported() {
// If pushState is supported, return true, else return false.
return !!(window.history && window.history.pushState);
}
@delputnam
delputnam / play_sound.sh
Last active December 17, 2015 07:48
Shell script for Mac OS X to raise volume slightly, play an MP3, and lower the volume again. I use it with Alfred's workflows to trigger the sound when I press a certain key combination. It's really just for fun.
osascript -e "set Volume 3.5"
afplay ~/Dropbox/Sounds/itssofluffy.mp3
osascript -e "set Volume 1.25"
@delputnam
delputnam / wordpress_post_exists.php
Last active August 4, 2018 09:22
Quick check to determine if a WordPress post exists using the post_name (slug) and post_type (defaults to 'post'). Returns the post ID if found, or 0 (zero) if not found.
/**
* Determine if a post exists based on post_name and post_type
*
* @param $post_name string unique post name
* @param $post_type string post type (defaults to 'post')
*/
function post_exists( $post_name, $post_type='post' ) {
global $wpdb;
@delputnam
delputnam / gist:5601170
Created May 17, 2013 18:55
To set a WordPress custom post type menu icon in a plugin include this in the args array when registering a custom post type.
'menu_icon' => plugins_url('images/custom-post-type-icon.png', __FILE__)
@delputnam
delputnam / functions.php
Created May 20, 2013 18:36
Get all WordPress posts of a certain type that have been published.
$query = new WP_Query( array(
'post_type' => 'event_type',
'post_status' => 'publish',
'nopaging' => true
) );
while ( $query->have_posts() ) : $query->the_post();
// Do something with the post here...
endwhile;
wp_reset_postdata();
@delputnam
delputnam / gist:6308052
Last active December 21, 2015 12:49
Get the first element of an array using php.
This resets the array's internal pointer to the first element:
reset( $array );
This does not modify the original array, but does make a copy of it, only use it for small arrays:
array_shift(array_values($array));
module Jekyll
class PostPublisher < Generator
safe false
def replace(filepath, regexp, *args, &block)
content = File.read(filepath).gsub(regexp, *args, &block)
File.open(filepath, 'wb') { |file| file.write(content) }
end
def generate(site)
@delputnam
delputnam / collections_filter.rb
Last active August 29, 2015 14:03
This is a liquid filter for Jekyll that will filter out individual collection items based on arbitrary yaml front matter variables.
# collections_filter.rb
#
# Filter individual Jekyll collections items based on arbitrary yam front matter variables.
#
# input - the collection array
# property - key to filter by
# value - desired value
#
# Returns the filtered array of objects
#
@delputnam
delputnam / collections_sort.rb
Last active January 29, 2023 15:38
This is a liquid filter for Jekyll that will sort collections based on arbitrary yaml front matter variables.
# collections_sort.rb
#
# Sort Jekyll collections items based on arbitrary yaml front matter variables.
#
# example usage:
#
# if you want to sort a collection based on a yaml variable of "order":
#
# {% assign filtered_events = site.my_collection | collection_sort: 'order' %}
#