Skip to content

Instantly share code, notes, and snippets.

View benbalter's full-sized avatar
Verified

Ben Balter benbalter

Verified
View GitHub Profile
@benbalter
benbalter / conditionally-load-jquery.js
Created April 4, 2011 18:05
Conditionally Load jQuery
// Conditionally Load jQuery (javascript)
// Source: https://gist.github.com/gists/902090/
var init, maybeLoadJq;
init = function() {
jQuery(document).ready(function() {
alert('Your Code Here');
});
};
@benbalter
benbalter / Google-analytics-virtual-event-tracking-code.js
Created April 4, 2011 18:13
Google Analytics virtual event tracking code for external links, downloads, and mailtos using jQuery.
//Mailto tracking code
$('a[href^="mailto\:"]').click(function() {
_gaq.push(['_trackEvent','Email', 'Click', $(this).attr('href') ]);
});
//Download Tracking Code
$('a[href$="zip"],a[href$="pdf"],a[href$="doc"],a[href$="docx"],a[href$="xls"],a[href$="xlsx"],a[href$="ppt"],a[href$="pptx"],a[href$="txt"],a[href$="csv"]').click(function() {
var u = $(this).attr('href'); _gaq.push(['_trackEvent','Download', u.match(/[^.]+$/), u ]);
});
@benbalter
benbalter / Conditionally-load-Google-Analytics.js
Created April 4, 2011 18:34
Conditionally load Google Analytics Tracking Code
//Conditionally load Google Analytics tracking code
//GA code optimized by Html5boiler plate -- https://github.com/paulirish/html5-boilerplate
if ( !window._gat || !window._gat._getTracker ) {
var _gaq=[["_setAccount","UA-XXX-1"],["_trackPageview"]];
(function(d,t){var g=d.createElement(t),s=d.getElementsByTagName(t)[0];g.async=1;
g.src=("https:"==location.protocol?"//ssl":"//www")+".google-analytics.com/ga.js";
s.parentNode.insertBefore(g,s)}(document,"script"));
}
@benbalter
benbalter / ga-jetpack-social.php
Last active September 26, 2015 07:07
Google Analytics Tracking of JetPack (Sharedaddy) Social Engagement
<?php
/**
* Plugin Name: Jetpack (Sharedaddy) Google Analytics Tracking
* Description: Allows tracking of Facebook and Twitter shares in Google Analytics Social Tracking
* Author: Benjamin J. Balter
* Author URI: http://ben.balter.com
* Version: 0.1
*/
/**
@benbalter
benbalter / remove-sexybookmarks.php
Created October 18, 2011 12:36
Remove SexyBookmarks from WP Resume pages
function remove_shrsb () {
remove_filter('the_content', 'shrsb_position_menu');
}
function wpr_add_shrsb() {
add_filter('the_content', 'shrsb_position_menu');
}
add_action( 'wp_resume_shortcode_pre', 'wpr_remove_shrsb' );
add_action( 'wp_resume_shortcode_post', 'wpr_add_shrsb' );
@benbalter
benbalter / enable-sb-metabox.php
Created October 18, 2011 12:43
Enable SexyBookmarks metabox on resume positions
function wpr_add_sb_metabox() {
if( !function_exists( 'shrsb_get_current_user_role' ) ||
( shrsb_get_current_user_role() != "Administrator" && shrsb_get_current_user_role() != "Editor")
)
return false;
add_meta_box( 'hide_options_meta', __( 'Shareaholic', 'shrsb' ), '_hide_options_meta_box_content', 'wp_resume_position', 'advanced', 'high' );
}
@benbalter
benbalter / top-help-users.php
Created December 28, 2011 18:10
Top Help Users Widget
<?php
/*
Plugin Name: Top Help Users
Description: Widget to display top users of help.hackshackers.com by reputation
Author: Benjamin J. Balter
Version: 1.0
Author URI: http://ben.balter.com
*/
class Top_Help_Users_Widget extends WP_Widget {
@benbalter
benbalter / recent-answers-widget.php
Created January 5, 2012 18:13
Recently Answered Questions
<?php
/*
Plugin Name: Help - Recently Answered Questions
Description: Widget to display recently answers questions on help.hackshackers.com
Author: Benjamin J. Balter
Version: 1.0
Author URI: http://ben.balter.com
*/
class Recent_Answers_Widget extends WP_Widget {
@benbalter
benbalter / wp-db.tutorial.php
Created January 13, 2012 18:41
WordPress DB Tutorial
<?php
//absolute path to wp-load.php, or relative to this script
//e.g., ../wp-core/wp-load.php
include( 'trunk/wp-load.php' );
//grab the WPDB database object, using WP's database
//more info: http://codex.wordpress.org/Class_Reference/wpdb
global $wpdb;
@benbalter
benbalter / display-custom-fields.php
Created January 15, 2012 16:03
Display Custom Fields
function content_filter( $content ) {
global $post;
$output = array();
$taxs = get_taxonomies( array( 'object_type' => array( $post->post_type ) ) );
foreach ( $taxs as $tax ) {
$tax = get_taxonomy( $tax );
$terms = get_the_term_list( $post->ID, $tax->name, null, ', ' );