Skip to content

Instantly share code, notes, and snippets.

View mattboon's full-sized avatar

Matt Berridge mattboon

View GitHub Profile
@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: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: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: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: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:3184843
Created July 26, 2012 21:58
WordPress- Include template using shortcode
<?
// include template using WP shortcode
function my_shortcode_include() {
ob_start();
// include your template e.g. /inc/random-panel.php
get_template_part('inc/random-panel');
$output_string = ob_get_contents();
ob_end_clean();
return $output_string;
@mattboon
mattboon / gist:3250150
Created August 3, 2012 18:20
WordPress - Events and Projects post types each with categories
<?
// EVENTS
add_action('init', '_init_event_post_type');
function _init_event_post_type() {
// Create taxonomy
register_taxonomy(
'event_category',
@mattboon
mattboon / gist:3577343
Created September 1, 2012 15:30
WordPress - Create in-section navigation for a given (hierarchical) post type
<?php
// Return link by post ID
// -------------------------------------------------------------
function link_by_id($post_id) {
echo '<a href="'.get_permalink($post_id).'">'.get_the_title($post_id).'</a>';
}
// Return the root parent ID
// -------------------------------------------------------------
@mattboon
mattboon / gist:3637228
Created September 5, 2012 14:11
Opt-in Typography
/*----------------------------------------------------------------------------------------*/
/* Opt-in typography - http://goo.gl/H6sGd
* Zero off common semantic elements to stop re-definition
* Use .text class on the parent of anything requiring text styles
/*----------------------------------------------------------------------------------------*/
$baseline: 1.5em;
@mixin zero-text-elements {
h1, h2, h3, h4, h5, h6, blockquote, pre,
@mattboon
mattboon / gist:3780739
Created September 25, 2012 09:01
WordPress - Local Admin CSS broken
<?
// no idea why this works but add to wp-config.php
define('SCRIPT_DEBUG', true);