Skip to content

Instantly share code, notes, and snippets.

View thadallender's full-sized avatar

Thad Allender thadallender

View GitHub Profile
@thadallender
thadallender / filter post class custom tax
Created June 4, 2013 22:27
Filter post_class to return terms from a custom taxonomy in WordPress
function custom_taxonomy_post_class( $classes, $class, $ID ) {
$taxonomy = 'pcategory';
$terms = get_the_terms( (int) $ID, $taxonomy );
if( !empty( $terms ) ) {
foreach( (array) $terms as $order => $term ) {
@thadallender
thadallender / gpp-bulk-convert-post-meta-keys.php
Created June 14, 2013 13:39
Bulk convert any number of custom post meta keys for all posts in a specific WordPress post type. Change the $posttype, $old_prefix, $new_prefix and the $keys array at the top of the plugin file. Important: This plugin fires on the init hook, so only run it once (deactivate this plugin immediately after all custom post meta keys have been updated.
<?php
/**
* Plugin Name: GPP Bulk Convert Post Meta Once
* Plugin URI: http://graphpaperpress.com
* Description: Converts post meta from one key format to another
* Author: Thad Allender
* Author URI: http://graphpaperpress.com
* Version: 1.0
* Text Domain: gpp
@thadallender
thadallender / derive-version-number.php
Created July 15, 2013 14:08
Derive version number from WordPress theme style.css
<?php
/**
* Get theme version number from WP_Theme object (cached)
*/
function gpp_get_theme_version() {
$theme_file = get_template_directory() . '/style.css';
$theme = new WP_Theme( basename( dirname( $theme_file ) ), dirname( dirname( $theme_file ) ) );
return $theme->get( 'Version' );
@thadallender
thadallender / wp-excerpt.php
Created January 21, 2014 03:37
Change WordPress excerpt length. Add this to your active theme's functions.php file. Change 36 to your desire.
function my_excerpt_length( $length ) {
return 36;
}
add_filter( 'excerpt_length', 'my_excerpt_length' );
@thadallender
thadallender / wp-change-read-more
Created January 21, 2014 04:10
Use this to change the read more text in WordPress. Change &hellip; to anything you want. Add this snippet to your theme's functions.php file.
function new_excerpt_more( $more ) {
return '&hellip;';
}
add_filter( 'excerpt_more', 'new_excerpt_more' );
@thadallender
thadallender / 5-col-grid-sell-media
Created February 3, 2014 22:21
Change from a 3 column to 5 column grid for Sell Media archives
.sell-media .sell-media-grid { width: 18%; }
.sell-media .sell-media-grid:nth-child(5n) { margin-right: 0; }
.sell-media .sell-media-grid:nth-child(3n), .sell-media .sell-media-grid .end { margin-right: 2%; }
.sell-media .sell-media-grid:nth-child(5n+1) { clear: left; }
.sell-media .sell-media-grid:nth-child(3n+1) { clear: none; }
@thadallender
thadallender / customize-grid
Created February 5, 2014 20:24
Grid tweak for 6 items in Storyteller
.fromblog-post, .blog-grid .hentry {
width: 32%;
}
.fromblog-post:nth-child(3n+1){
clear:left;
}
@thadallender
thadallender / style.css
Created February 20, 2014 19:21
WordPress child theme style.css
/*
Theme Name: Stock Photography Child
Theme URI: http://graphpaperpress.com/themes/stock-photography-child/
Description: Stock Photography Child Theme
Author: Thad Allender
Author URI: http://thadallender.com
Template: stock-photography
Version: 1.0.0
Tags: light, dark, two-columns, right-sidebar, responsive-layout, accessibility-ready
Text Domain: stock-photography-child
@thadallender
thadallender / Resize WordPress images dynamically
Created March 27, 2014 23:46
Resize WordPress images on the fly using core functions
/**
* Resize an image to specified dimensions
* @return (string) path to product image or feature image
*/
function my_resize_image( $post_id=null, $width=null, $height=null, $crop=true ) {
// get path to featured image
$featured_image_id = get_post_thumbnail_id( $post_id );
$featured_image_path = get_attached_file( $featured_image_id );
@thadallender
thadallender / customize-sell-media-continue-shopping.php
Last active August 29, 2015 13:58
To customize the "continue shopping" text on the Sell Media checkout page, paste this code into your active theme's functions.php or create your own plugin with your tweaks containing this code.
<?php
/**
* Plugin Name: Sell Media Continue Shopping Filter
* Plugin URI: https://graphpaperpress.com/plugins/sell-media/
* Description: Filter to Sell Media "Continue shopping" links
* Version: 1.0.0
* Author: Thad Allender
* Author URI: https://graphpaperpress.com
* Author Email: support@graphpaperpress.com
* Text Domain: sell_media