Skip to content

Instantly share code, notes, and snippets.

View benhuson's full-sized avatar

Ben Huson benhuson

View GitHub Profile
@benhuson
benhuson / class-frontend.php
Created February 3, 2012 15:48
WordPress SEO plugin patch
<?php
class WPSEO_Frontend {
function __construct() {
$options = get_wpseo_options();
add_action( 'wp_head', array(&$this, 'head'), 1, 1 );
remove_action( 'wp_head', 'rel_canonical' );
@benhuson
benhuson / Post_Taxonomy_Columns_And_Filter
Created February 17, 2012 11:21
Framework for adding taxonomy filter and column to WordPress manage post admin pages.
<?php
class Post_Taxonomy_Columns_And_Filter {
/**
* Constructor
*/
function Post_Taxonomy_Columns_And_Filter() {
add_filter( 'manage_edit-mycustomposttype_columns', array( $this, 'manage_mycustomposttype_columns' ) );
add_action( 'manage_mycustomposttype_posts_custom_column', array( $this, 'show_mycustomposttype_columns' ) );
@benhuson
benhuson / get_the_term_list_breadcrumbs.php
Created February 17, 2012 14:55
get_the_term_list_breadcrumbs() - Same as get_the_term_list() but outputs a terms parents as part of the link.
/**
* Get the Term List Breadcrumbs
* Same as get_the_term_list() but outputs a terms parents as part of the link.
* Useful when you have many subcategories all with the same name.
*/
function get_the_term_list_breadcrumbs( $id = 0, $taxonomy, $before = '', $sep = '', $after = '', $breadcrumb_sep = ' &rarr; ' ) {
$terms = get_the_terms( $id, $taxonomy );
if ( is_wp_error( $terms ) )
@benhuson
benhuson / gist:2043878
Created March 15, 2012 12:00
WPEC normal email fields on wpsc-shopping_cart_page.php
If you remove the following code from the wpsc-shopping_cart_page.php template, I think it works normally:
Around line 358:
<?php
}elseif( $wpsc_checkout->checkout_item->unique_name == 'billingemail'){ ?>
<?php $email_markup =
"<div class='wpsc_email_address'>
<p class='" . wpsc_checkout_form_element_id() . "'>
<label class='wpsc_email_address' for='" . wpsc_checkout_form_element_id() . "'>
@benhuson
benhuson / jquery.touchcarousel-1.0.patch.js
Created March 28, 2012 18:00
TouchCarousel - Detach
/* Detach carousel - same as destroy but content is not removed */
detach: function() {
this.stopAutoplay();
this._itemsWrapper.unbind(this._downEvent);
$(document).unbind(this._moveEvent).unbind(this._upEvent);
$(window).unbind(this._resizeEvent);
if(this.settings.keyboardNav) {
$(document).unbind("keydown.touchcarousel");
}
if (this._dragContainer.parent().hasClass('touchcarousel-wrapper')) {
@benhuson
benhuson / gist:2576414
Created May 2, 2012 13:06
Fix scale on rotate issue on iPad/iPhone
/**
* Fix scale on rotate issue
*/
if (navigator.userAgent.match(/iPhone/i) || navigator.userAgent.match(/iPad/i)) {
var viewportmeta = document.querySelector('meta[name="viewport"]');
if (viewportmeta) {
viewportmeta.content = 'width=device-width, minimum-scale=1.0, maximum-scale=1.0, initial-scale=1.0';
document.body.addEventListener('gesturestart', function () {
viewportmeta.content = 'width=device-width, minimum-scale=0.25, maximum-scale=1.6';
}, false);
@benhuson
benhuson / gist:2576426
Created May 2, 2012 13:09
Useful CSS
/* Prevent text scaling on rotate for iPad/iPhone */
html { -webkit-text-size-adjust: none; }
@benhuson
benhuson / sitepress.class.patch.php
Created July 6, 2012 11:16
WPML Serialised Custom Fields Patch
diff --git a/sitepress.class.php b/sitepress.class.php
index d5b2802be9a9de8b64244e889328b3e2ad776c9b..ecd861877107f00a7b111c3477bd65df12e86e6f 100644
--- a/sitepress.class.php
+++ b/sitepress.class.php
@@ -2775,7 +2775,7 @@ class SitePress{
// if the list of values has 1 element run update
// this will either ADD or UPDATE the value on the translated document
if(count($meta_values) == 1){
@benhuson
benhuson / gist:3090587
Created July 11, 2012 14:09
Term Taxonomy meta example
/**
* Add extra category fields
* Requires the Term_Taxonomymeta plugin
*/
function add_category_excerpt_fields( $category ) {
if ( ! class_exists( 'Term_Taxonomymeta' ) )
return;
$category_metadata = get_metadata( 'term_taxonomy', $category->term_id, 'excerpt', true );
?>
<tr class="form-field">
@benhuson
benhuson / gist:3635796
Created September 5, 2012 12:18
Add wpml-{ICL_LANGUAGE_CODE} class to body tag #WordPress #WPML
/**
* Add wpml-{ICL_LANGUAGE_CODE} class to body tag
*/
function wpml_body_class( $classes ) {
if ( defined( 'ICL_LANGUAGE_CODE' ) )
$classes[] = 'wpml-' . strtolower( ICL_LANGUAGE_CODE );
return $classes;
}
add_filter( 'body_class', 'wpml_body_class' );