Skip to content

Instantly share code, notes, and snippets.

View jmdodd's full-sized avatar

Jennifer M. Dodd jmdodd

View GitHub Profile
@jmdodd
jmdodd / gist:1139941
Created August 11, 2011 15:29
Add human-readable classes to wp_nav_menu()
<?php
if ( ! function_exists( 'ucc_nav_menu_css_class' ) ) {
function ucc_nav_menu_css_class( $classes, $item, $args ) {
$class = sanitize_title( $item->title );
$classes[] = 'menu-item-' . $class;
return $classes;
} }
add_filter( 'nav_menu_css_class', 'ucc_nav_menu_css_class', 10, 3 );
@jmdodd
jmdodd / gist:1142941
Created August 12, 2011 20:37
__return_empty_string() and use in filters
<?php
if ( ! function_exists( '__return_empty_string' ) ) {
function __return_empty_string() {
return '';
} }
add_filter( 'the_generator', '__return_empty_string' );
?>
@jmdodd
jmdodd / gist:1142990
Created August 12, 2011 21:02
Add custom post type and taxonomy counts in the Right Now Dashboard widget
<?php
// Based on http://svn.automattic.com/wordpress/trunk/wp-admin/includes/dashboard.php
if ( ! function_exists( 'ucc_right_now_content_table_end' ) ) {
function ucc_right_now_content_table_end() {
$args = array(
'public' => true ,
'_builtin' => false
);
$output = 'object';
@jmdodd
jmdodd / gist:1318760
Created October 27, 2011 04:08
Filter tweet timestamp in Ozh' Tweet Archiver to match blog's specified GMT offset
<?php
if ( ! function_exists( 'ucc_ozh_ta_insert_tweets_post_filter' ) ) {
function ucc_ozh_ta_insert_tweets_post_filter( $postarr ) {
$offset = get_option( 'gmt_offset' ) * 3600;
$date = date( 'Y-m-d H:i:s', strtotime( $postarr['post_date'] . ' UTC' ) + $offset );
$postarr['post_date'] = $date;
return $postarr;
} }
@jmdodd
jmdodd / gist:1319302
Created October 27, 2011 11:18
Unmask file locations in a WordPress Multisite installation (for WP 3.1+)
<?php
if ( ! function_exists( 'ucc_upload_dir_wp31' ) ) {
function ucc_upload_dir_wp31( $uploads ) {
// Set these options in Network Admin > Sites > Edit > Settings > Upload Path and Upload Url Path.
$upload_path = get_option( 'upload_path' ); // Example: /home/username/public_html/wp-content/blogs.dir/2/files
$upload_url_path = get_option( 'upload_url_path' ); // Example: http://sub.domain.com/wp-content/blogs.dir/2/files
$uploads['baseurl'] = $upload_url_path;
$uploads['url'] = $upload_url_path . $uploads[ 'subdir' ];
@jmdodd
jmdodd / gist:1319304
Created October 27, 2011 11:20
Unmask file locations in a WordPress Multisite installation (for WP 3.0)
<?php
if ( ! function_exists( 'ucc_upload_dir_wp30' ) ) {
function ucc_upload_dir_wp30( $uploads ) {
// Set these options in Super Admin > Sites > Edit > Upload Path and Upload Url Path.
$upload_path = get_option( 'upload_path' ); // Example: /home/username/public_html/wp-content/blogs.dir/2/files
$fileupload_url = get_option( 'fileupload_url' ); // Example: http://sub.domain.com/wp-content/blogs.dir/2/files
$uploads['baseurl'] = $fileupload_url;
$uploads['url'] = $fileupload_url . $uploads[ 'subdir' ];
@jmdodd
jmdodd / gist:1320216
Created October 27, 2011 17:28
Add Post Format to the $post taxonomy array
<?php
$postarr['tax_input']['post_format'] = 'post-format-aside';
$postarr['tax_input']['post_format'] = 'post-format-chat';
$postarr['tax_input']['post_format'] = 'post-format-gallery';
$postarr['tax_input']['post_format'] = 'post-format-link';
$postarr['tax_input']['post_format'] = 'post-format-image';
$postarr['tax_input']['post_format'] = 'post-format-quote';
$postarr['tax_input']['post_format'] = 'post-format-status';
$postarr['tax_input']['post_format'] = 'post-format-video';
@jmdodd
jmdodd / gist:1403950
Created November 29, 2011 08:06
Add post format support to Theme Hybrid via child theme
<?php
add_theme_support( 'post-formats', array( 'aside', 'chat', 'gallery', 'image', 'link', 'quote', 'status', 'video', 'audio' ) );
if ( ! function_exists( 'ucc_hybrid_entry_title' ) ) {
function ucc_hybrid_entry_title( $title ) {
global $post;
// Get rid of title on Status (tweets).
if ( has_post_format( 'status' ) ) {
@jmdodd
jmdodd / gist:1404031
Created November 29, 2011 08:38
Unfilter links in captions in the WordPress Add Image dialogue
<?php
if ( ! function_exists( 'ucc_fix_image_add_caption_shortcode' ) ) {
function ucc_fix_image_add_caption_shortcode( $shcode, $html ) {
$shcode = str_replace( array( '&gt;', '&lt;', '&quot;', '&#039;' ),
array( '>', '<', '"', "'" ),
$shcode );
return( $shcode );
} }
@jmdodd
jmdodd / gist:1407265
Created November 30, 2011 00:04
Remove curly quotes on save
<?php
if ( ! function_exists( 'ucc_remove_curly_quotes' ) ) {
function ucc_remove_curly_quotes( $content ) {
$content = str_replace( array( '&#8220;', '&#8221;', '“', '”', '“', '”' ), '"', $content );
$content = str_replace( array( '&#8216;', '&#8217;', '‘', '’', '‘', '’' ), "'", $content );
return $content;
} }
add_filter( 'content_save_pre', 'ucc_remove_curly_quotes' );