Skip to content

Instantly share code, notes, and snippets.

View chriskoelle's full-sized avatar

Chris Koelle chriskoelle

View GitHub Profile
<?php
class FB_Like_Widget extends WP_Widget {
private static $scripts_added;
public function __construct() {
parent::__construct(
'fb-like-box-widget', // ID
'Facebook Widget ', // Name
array(
;(function($) {
$.fn.extend({
stickyWidget: function(options) {
// Exit if there are no elements to avoid errors:
if (this.length === 0) {
return this;
}
var settings = $.extend({
@chriskoelle
chriskoelle / functions.php
Last active August 29, 2015 14:00
Wordpress trim "Private:" and "Protected:" from post titles
function nh_trim_post_titles($format) {
return '%s';
}
add_filter('protected_title_format', 'nh_trim_post_titles' );
add_filter('private_title_format', 'nh_trim_post_titles' );
@chriskoelle
chriskoelle / nh-oembed.php
Last active December 15, 2015 19:43
Wordpress oEmbed Customizations
<?php
/**
* Clear oEmbed Cache on save
* this is necessary in order to update the oembed output
*/
function nh_clear_oembed_caches($post_id) {
if ( wp_is_post_revision( $post_id ) ) return;
global $wp_embed;
$wp_embed->delete_oembed_caches($post_id);
}
@chriskoelle
chriskoelle / .htaccess
Created March 10, 2014 00:29
Disable compatibility mode in IE
Header set X-UA-Compatible "IE=edge"
@chriskoelle
chriskoelle / functions.php
Created January 8, 2014 03:30
Wordpress Cleanup wp_nav_menu Classes
// Cleanup some of the extra menu item classes added to wp_nav_menu
function nh_allowed_menu_item_classes($classes, $item) {
// Get custom classes added from within the menus admin page
$new_classes = (array) get_post_meta( $item->ID, '_menu_item_classes', true );
// Consolidate the assorted "current..." classes
$current_classes = preg_grep('/current/', $classes);
if(!empty($current_classes)) $new_classes[] = 'current';
@chriskoelle
chriskoelle / shuffle.js
Created December 27, 2013 22:46
Javascript Array Shuffle
Array.prototype.shuffle = function() {
var i = this.length, j, temp;
if ( i === 0 ) return this;
while ( --i ) {
j = Math.floor( Math.random() * ( i + 1 ) );
temp = this[i];
this[i] = this[j];
this[j] = temp;
}
return this;
@chriskoelle
chriskoelle / functions.php
Created December 5, 2013 20:57
Wordpress Change Embed Shortcode Defaults
function new_embed_sizes() {
return array( 'width' => 640, 'height' => 9999);
}
add_filter('embed_defaults', 'new_embed_sizes');
@chriskoelle
chriskoelle / functions.php
Created December 5, 2013 20:17
Wordpress Body Class Cleanup Removes some of the rerely used classes output by Wordpresses body_class function in order to cut down on markup
function cleanup_post_class( $classes, $class, $post_id ) {
foreach($classes as $key => $class):
if(preg_match('/(^tag)|(^post)|(hentry)|(uncategorized)|(status)/', $class)) unset($classes[$key]);
endforeach;
$classes[] = 'post-'.$post_id;
return $classes;
}
add_filter('post_class', 'cleanup_post_class', 10 , 3);
@chriskoelle
chriskoelle / custom_meta_box.php
Last active December 30, 2015 04:09
Custom Meta Box - Custom Meta Types - for use with Jared Atchison's Custom Metaboxes and Fields for WordPresshttps://github.com/jaredatch/Custom-Metaboxes-and-Fields-for-WordPress
<?php
// Custom Post Type Dropdown
function cmb_post_type_dropdown($field, $meta) {
wp_dropdown_pages(array(
'show_option_none' => '-- Select One ---',
'name' => $field['id'],
'id' => $field['id'],
'post_type' => $field['post_type'],
'selected' => $meta
));