Skip to content

Instantly share code, notes, and snippets.

View jeremyfelt's full-sized avatar
🍕
Look at that pizza emoji!

Jeremy Felt jeremyfelt

🍕
Look at that pizza emoji!
View GitHub Profile
@jeremyfelt
jeremyfelt / gist:1718393
Created February 1, 2012 18:10
Dynamic Multiple Column Unordered Lists
( function($){
var parent_ul_selector = '#menu-header-navigation', /* Selector for the nav menu you're working with. */
child_li_selector = '.nav-mid-item', /* Selector for child <li> elements this applies to. */
new_div_id_prefix = 'menu-replace', /* ID prefix for the newly created <div> elements. */
new_div_class = 'menu-replaced', /* Class for the newly created <div> elements. */
column_selector_prefix = 'column', /* Selector prefix used for newly created <ul> elements. */
new_ul_class = 'sub-menu-replace', /* Class for newly created <ul> elements. */
max_columns = 3, /* Maximum columns, pending available list items */
min_column_size = 2, /* Minimum items in the shortest column before # of columns is reduced. */
div_count = 0, /* For C
@jeremyfelt
jeremyfelt / gist:1960725
Created March 2, 2012 19:31
Conditional WordPress stylesheets
<?php
/* Register our IE specific stylesheets. */
wp_register_style( 'prefix-ie7-only', get_template_directory_uri() . '/css/ie7.css' );
wp_register_style( 'prefix-ie8-only', get_template_directory_uri() . '/css/ie8.css' );
wp_register_style( 'prefix-ie9-only', get_template_directory_uri() . '/css/ie.css' );
/* Use the global wp_styles object to add our conditional statements due to the lack
* of conditional support in wp_register_style
*/
@jeremyfelt
jeremyfelt / gist:2306214
Created April 4, 2012 22:42
Resize the blogroll images
<?php
add_filter( 'get_bookmarks', 'prefix_resize_blogroll_images' );
function prefix_resize_blogroll_images( $output ) {
for ( $i = 0, $total = sizeof( $output ); $i < $total; $i++ ) {
if ( 'http' == substr( $output[ $i ]->link_image, 0, 4 ) )
$output[ $i ]->link_image = wpcom_vip_get_resized_remote_image_url( $output[ $i ]->link_image, 72, 51, false );
else
$output[ $i ]->link_image = '';
}
<?php
/**
* Set API URLS
*/
function accessTokenURL() { return 'https://api.twitter.com/oauth/access_token'; }
function authenticateURL() { return 'https://api.twitter.com/oauth/authenticate'; }
function authorizeURL() { return 'https://api.twitter.com/oauth/authorize'; }
function requestTokenURL() { return 'https://api.twitter.com/oauth/request_token'; }
@jeremyfelt
jeremyfelt / gist:2347611
Created April 10, 2012 00:33
Display excerpt with some tags
<?php
/* Used to display the excerpt of a post across the site. Written very closely with
* wp_trim_excerpt, but instead of stripping out all tags, we want to make sure that
* some basic style still remains as this display function will be used for the index
* and archive templates, not something as plain as a feed or meta description. */
function prefix_display_excerpt( $number_of_words = 55 ) {
global $post;
$content = get_the_content();
$content = strip_shortcodes( $content );
$content = preg_replace( '@<(script|style)[^>]*?>.*?</\\1>@si', '', $content );
@jeremyfelt
jeremyfelt / gist:2353300
Created April 10, 2012 18:05
Strip whitespace between HTML tags in wp_nav_menu()
<?php
/* Modify the output of list items in the header navigation menu.
*
* Remove the whitespace between HTML tags. Required specifically for better
* behavior when list items are inline-block in our main nav menu and need
* the browsers to adhere to exact margins.
*
* NOTE: filter name changes depending on your menu - this one works for 'navigation_items'
*/
@jeremyfelt
jeremyfelt / gist:2372981
Created April 13, 2012 02:14
Script the scripts
<?php
$default_html = '<script type="text/javascript">document.write(\'<scr\' + \'ipt type="text/javascript">ad_urls["%ad_frame_id%"] = "%url%";</scr\' + \'ipt>\');</script>';
@jeremyfelt
jeremyfelt / functions.php
Created April 14, 2012 19:20
Filters enabled in Automatic Featured Image Posts
<?php
/* A brief overview of filters that are now available in Automatic Featured Image Posts.
*
* These allow easy overriding of the default post title, categories, and content before
* the new post is created, while still maintaining the core priority of the plugin,
* which is to add a new post with a featured image assigned to it */
add_filter( 'afip_new_post_title', 'myprefix_change_afip_post_title', 10, 2 );
/* Adds 'Magic Photo: ' to the front of every auto generated post tile from
* Automatic Featured Image Posts */
function myprefix_change_afip_post_title( $post_title, $attachment_id ) {
@jeremyfelt
jeremyfelt / gist:2625099
Created May 7, 2012 00:11
A very basic example of register_post_type() in WordPress
<?php
/*
* Creates a custom post type with the key 'prefix_post_type', with a basic
* configuration that provides for public access on the front end and admin.
*
*/
add_action( 'init', 'prefix_register_post_type' );
function prefix_register_post_types() {
$public_pt_args = array(
'label' => 'My Post Type',
@jeremyfelt
jeremyfelt / gist:2625156
Created May 7, 2012 00:32
The results of 'public' => true and 'public' => false in register_post_type()
<?php
/* If public is not specified when registering a custom post type, false
* is used by default. */
$non_public_pt_args = array( 'public' => false );
/* The above is the same as specifying the following. */
$non_public_pt_args = array(
'public' => false,
'publicly_queryable' => false,
'exclude_from_search' => true,