Skip to content

Instantly share code, notes, and snippets.

View szbl's full-sized avatar

Sizeable, Inc. szbl

View GitHub Profile
@szbl
szbl / wp-reverse-comments.php
Created January 31, 2013 01:31
One line of code that will allow you to reverse the order of comment output from ascending to descending post date.
<?php
// you can do this in your functions.php file, a plugin file
// or even in your theme before comments are displayed:
add_filter( 'comments_array', 'array_reverse' );
?>
@szbl
szbl / jquery-email-obfuscation.js
Created March 4, 2013 20:28
Updated email obfuscation.
jQuery( document ).ready(function($){
//Email Encrypt
$(".email").each(function(){
var ats, dots, address, i;
ats = [ ' at ', ' (at) ', ' [at] ' ];
dots = [ ' dot ', ' (dot) ', ' [dot] ' ];
address = $(this).html();
for ( i = 0; i < ats.length; i++ )
{
RewriteEngine On
RewriteCond %{HTTP_HOST} ^blog.domain.com
RewriteRule ^(.*)$ http://www.domain.com/blog/$1 [R=301,L]
<?php
/*
Plugin Name: Sizeable Body Classer
Author: theandystratton
Author URI: http://sizeableinteractive.com
Description: Add to your functions.php to have quick functions for adding body classes. Simply run the following code before get_header(): szbl_add_body_class( 'some-body-class' );
Version: 0.1
License: GPL2
*/
function szbl_add_body_class( $class, $return = false )
@szbl
szbl / enter-title-here.php
Last active December 15, 2015 07:49
Easily edit the "Enter Title Here" message when editing a post based on post type slug. This example uses "szbl-location" as seen in my WordCamp San Diego 2013 presentation.
<?php
add_filter( 'enter_title_here', 'szbl_enter_title_here' );
function szbl_enter_title_here( $title )
{
switch ( get_post_type() )
{
case 'szbl-location':
$title = 'Enter Location Name';
break;
}
@szbl
szbl / admin-columns-hooks.php
Last active December 15, 2015 07:49
How to add custom admin columns in WordPress for a sample post type "szbl-location" – this is from my WordCamp San Diego 2013 presentation. This is a bit simplified.
<?php
/*
Add the actual columns to the szbl-location edit listing admin screen.
*/
add_filter( 'manage_edit-szbl-location_columns', 'szbl_manage_edit_columns', 10 );
function szbl_manage_edit_columns( $cols )
{
$new_cols = array(
'cb' => '<input type="checkbox">',
'title' => __( 'Location Name' ),
@szbl
szbl / custom-taxonomy-admin-col.php
Last active December 15, 2015 07:49
Adding taxonomy column to custom post type listing for my WordCamp San Diego 2013 presentation on Advanced Custom Post Types.
<?php
add_action( 'init', 'szbl_register_tax' );
function szbl_register_tax()
{
register_taxonomy(
'szbl-location-category',
array( 'szbl-location' ),
array(
'labels' => array(
'name' => __( 'Store Categories' ),
@szbl
szbl / pull-cpt-with-taxonomy.php
Last active December 15, 2015 07:49
How to pull a custom post type and filter via custom taxonomy (for WordCamp San Diego 2013).
<?php
/*
Grab the top 5 locations with content tagged as "Featured"
and "Child Care" then output them in an ordered list.
*/
$locations = get_posts(array(
'post_type' => 'szbl-location',
'posts_per_page' => 5,
'orderby' => 'menu_order',
'order' => 'asc',
@szbl
szbl / modify-content-tags.php
Created March 23, 2013 07:05
Plugin to modify Content Tags to only apply to posts/pages. Also hides it's admin column. Shows extendibility within a plugin for my WordCamp San Diego 2013 presentation.
<?php
/*
This code could be placed in a plugin or your theme's functions.php file.
*/
add_filter( 'szbl_content_tags-settings-post_types', 'szbl_content_tags_post_types', 10 );
function szbl_content_tags_post_types( $post_types )
{
// only allow posts/pages to receive Content Tags.
return array( 'post', 'page' );
}
@szbl
szbl / cpt-icons.php
Last active December 15, 2015 07:49
Adding a custom post type icon from the CPT icon set. Icons and code from Randy Jensen: http://randyjensenonline.com/thoughts/wordpress-custom-post-type-fugue-icons/ WordCamp San Diego 2013
<?php
/*
Add custom icon with grayscale to color activation states.
Makes you more like core.
We're assuming this is included in your core plugin file
and the icon cpt-icon.png is in the same directory.
So, if this file were /wp-content/plugins/my-plugin/plugin.php