Skip to content

Instantly share code, notes, and snippets.

View madysondesigns's full-sized avatar

Sarah Whinnem madysondesigns

View GitHub Profile
In functions.php:
function load_podcast_from_slug($slug) {
echo "https://soundcloud.com/graphicdesignerpodcast" . $slug;
}
In single.php inside the loop:
load_podcast_from_slug($post->post_name);
@madysondesigns
madysondesigns / calc_years_since.php
Created April 5, 2016 01:02
Calculate years since
function calc_years_since($year) {
$since = date("Y") - $year;
if ($since == 1) {
$since .= " year";
} else {
$since .= " years";
}
echo $since;
@madysondesigns
madysondesigns / aws_cf_invalidate.rb
Last active August 29, 2015 14:10 — forked from jmlacroix/aws_cf_invalidate.rb
Invalidate Cloudfront objects from the command line.
# Forked from jmlacroix/aws_cf_invalidate.rb
# Modified to read s3 creds from the environment and the distribution id from arguments passed in.
require 'rubygems'
require 'hmac-sha1'
require 'net/https'
require 'base64'
s3_access=ENV['S3_ACCESS']
s3_secret=ENV['S3_SECRET']
@madysondesigns
madysondesigns / gist:9982968
Created April 4, 2014 20:56
Git Cheatsheet
Checking in/out:
$ git clone [project url] - get a copy of repo in a folder
$ git checkout [file] - check out last committed version of a file
$ git add --patch [file] - Step through each section of changes in a file with option to stage or not stage
$ git remote rm origin - remove origin
$ git remote add origin [url] - add origin
Working with Branches:
$ git branch [foo] - create branch named foo
@madysondesigns
madysondesigns / gist:8560821
Created January 22, 2014 15:33
WordPress Custom Template for a Single Post ID
// Hook into the single_template filter to use a custom template for one particular
// post and still have it appear in the regular blog archives, featured posts, etc.
// Template should be named 'single-[postID].php.
add_filter('single_template', 'widget_custom_post');
function widget_custom_post($template) {
global $post;
// If it's the desired post, override the standard template with custom.
@madysondesigns
madysondesigns / gist:5306705
Created April 4, 2013 00:29
WordPress blog check
//finally have a function to check if we're anywhere on the damned blog and only the blog
function is_blog() {
if ( get_post_type() == 'post' || is_post_type_archive( 'post' ) ) {
$blog = is_home() || is_archive() || is_single();
return $blog;
}
}
@madysondesigns
madysondesigns / gist:5217699
Created March 21, 2013 23:16
WordPress body classes
//print page and parent slugs for css classes
function page_slug_classes($classes) {
global $post;
$classes = array();
//get the slug of any parent pages
$parent_slug = basename(get_permalink($post->post_parent));
array_push($classes, $parent_slug);
//get the slug of the current page
@madysondesigns
madysondesigns / gist:3912634
Created October 18, 2012 15:39
Print taxonomy of WP post in loop
In functions.php:
function get_taxonomy() {
$taxonomy = wp_get_object_terms( $post->ID, '[taxonomy]', array("fields" => "names") );
$taxonomy = $taxonomy[0];
echo $taxonomy;
}
Have two taxonomies. Both work in WP admin, and can be displayed with get_the_term_list(). But one won't work with wp_tag_cloud().
Working taxonomy:
add_action( 'init', 'create_post_flags' );
function create_post_flags() {
$labels = array(
'name' => _x( 'Post Flags', 'taxonomy general name' ),
'singular_name' => _x( 'Post Flag', 'taxonomy singular name' ),
'search_items' => __( 'Search Post Flags' ),
@madysondesigns
madysondesigns / gist:3237574
Created August 2, 2012 14:46
Google Docs Forms
<script type="text/javascript">var submitted=false;</script>
//This is where thank you page/message is loaded. Replace onload function with jQuery hide/show or page redirect to separate page {window.location='thankyou.html';}.
<iframe name="hidden_iframe" id="hidden_iframe" style="display:none;" onload="if(submitted) {$('#formblock').hide(); $('#thankyou').fadeIn('fast');}"></iframe>
//replace form key with actual key from Google Docs
<form action="https://docs.google.com/a/betterment.com/spreadsheet/formResponse?formkey=dGlUczJTRUNjaHExOGtqZkVCYjVtR3c6MQ&amp;ifq" method="post" target="hidden_iframe" id="commentForm" onsubmit="submitted=true;">
<div id="formblock">
//recreate form fields and validation if needed