Skip to content

Instantly share code, notes, and snippets.

View mattboon's full-sized avatar

Matt Berridge mattboon

View GitHub Profile
@mattboon
mattboon / gist:3151186
Created July 20, 2012 15:02
WordPress - Example index page for custom post type
<?php
/*
Template Name: You post type
*/
?>
<?php get_header(); ?>
<?php get_template_part('inc/page-title'); ?>
<div class="main content" role="main">
<?php
// http://codex.wordpress.org/Function_Reference/query_posts
@mattboon
mattboon / gist:3143919
Created July 19, 2012 13:31
WordPress - Stop <img>s being wrapped in <p>s
<?php
function wpautop_forked($pee, $br = 1) {
if ( trim($pee) === '' )
return '';
$pee = $pee . "\n"; // just to make things a little easier, pad the end
$pee = preg_replace('|<br />\s*<br />|', "\n\n", $pee);
// Space things out a little
$allblocks = '(?:table|thead|tfoot|caption|col|colgroup|tbody|tr|td|th|div|dl|dd|dt|ul|ol|li
|pre|select|option|form|map|area|blockquote|img|address|math|style|input
@mattboon
mattboon / gist:2966839
Created June 21, 2012 16:26
WordPress - Get start and end date and format them
<?php
// event date
$dstart = get_field('event_date_start');
$dend = get_field('event_date_end');
if (!$dend) {
$dend = $dstart;
}
$start_year = date("o",strtotime($dstart));
$end_year = date("o",strtotime($dend));
@mattboon
mattboon / gist:2960966
Created June 20, 2012 17:05
WordPress - Verbose rules to fix /page/2 issues with Custom Post Types
<?php
// http://wordpress.stackexchange.com/a/16929/9244
add_action( 'init', 'wpse16902_init' );
function wpse16902_init() {
$GLOBALS['wp_rewrite']->use_verbose_page_rules = true;
}
add_filter( 'page_rewrite_rules', 'wpse16902_collect_page_rewrite_rules' );
function wpse16902_collect_page_rewrite_rules( $page_rewrite_rules )
@mattboon
mattboon / gist:2953889
Created June 19, 2012 12:36
WordPress - Remove / unregister taxonomy
<?php
add_action( 'init', 'unregister_taxonomy');
function unregister_taxonomy(){
global $wp_taxonomies;
$taxonomy = 'post_tag';
if ( taxonomy_exists( $taxonomy))
unset( $wp_taxonomies[$taxonomy]);
}
@mattboon
mattboon / gist:2929500
Created June 14, 2012 10:33
WordPress - Remove inline CSS from .wp-caption (plugin)
<?php
/*
Plugin Name: FixWpCaption
Plugin URI: #
Description: Removes inline CSS from .wp-caption
*/
class FixWpCaption{
public function __construct(){
add_filter('img_caption_shortcode', array($this, 'fixcaption'), 10, 3);
@mattboon
mattboon / gist:2929172
Created June 14, 2012 08:58
WordPress - Remove inline <img> sizes / attributes
<?php
// Remove <img> dimensions
// -------------------------------------------------------------
add_filter( 'post_thumbnail_html', 'remove_thumbnail_dimensions', 10 );
add_filter( 'image_send_to_editor', 'remove_thumbnail_dimensions', 10 );
add_filter( 'the_content', 'remove_thumbnail_dimensions', 10 );
function remove_thumbnail_dimensions( $html ) {
$html = preg_replace( '/(width|height)=\"\d*\"\s/', "", $html );
@mattboon
mattboon / gist:2929125
Created June 14, 2012 08:49
WordPress - Query / test the_excerpt
<?php
function my_query_excerpt($page) {
global $post;
$save_post = $post;
$post = get_post($page);
$output = '<p>' . get_the_excerpt() . '</p>';
$post = $save_post;
return $output;
}
@mattboon
mattboon / gist:2731316
Created May 19, 2012 16:01
jQuery - ResponsiveReel
// Simple Slideshow
$(function () {
var visibleClass = 'visible'; // no .
var currentClass = 'current'; // no .
var animationTime = 300; // fade duration
var containerClass = '.slides'; // class on container
var slideItem = 'img'; // what are we sliding?
var slideItems = $(containerClass).find(slideItem); // all slides
var slideNumbers = $(".slide-nav a"); // pagination numbers
var slideNext = $(".next"); // next link
@mattboon
mattboon / gist:2658869
Created May 11, 2012 10:31
WordPress - Add Tag ID column for post_tags
<?
// Remove columns from Tags section and add Tag ID
// -------------------------------------------------------------
add_filter('manage_edit-post_tag_columns', 'my_post_tag_columns', 5);
function my_post_tag_columns($defaults) {
$defaults['tag_id'] = 'Tag ID';
unset($defaults['description']);
unset($defaults['slug']);
return $defaults;