Skip to content

Instantly share code, notes, and snippets.

View thadallender's full-sized avatar

Thad Allender thadallender

View GitHub Profile
@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 / 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 / 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 / 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 ) {