Skip to content

Instantly share code, notes, and snippets.

View benhuson's full-sized avatar

Ben Huson benhuson

View GitHub Profile
@benhuson
benhuson / ios7-safari-height-issue
Last active April 22, 2016 10:10
Fix iOS 7 iPad Safari Landscape innerHeight/outerHeight layout issue
/**
* Add ipad IOS7 Classes
* Allows us to temporariliy try to fix the slight scroll 100% hack.
* http://stackoverflow.com/questions/19012135/ios-7-ipad-safari-landscape-innerheight-outerheight-layout-issue
*/
if (navigator.userAgent.match(/iPad;.*CPU.*OS 7_\d/i)) {
$('html').addClass('ipad ios7');
}
/**
# WordPress Project .gitignore
# Ignore system files
.DS_Store
# Ignore all files by default except `.gitignore` and `site` folder
/*
!/.gitignore
!/site/
var ipad_version = 0;
window.ondevicemotion = function(event) {
if (navigator.platform.indexOf("iPad") != -1) {
ipad_version = 1;
if (event.acceleration) ipad_version += window.devicePixelRatio;
}
window.ondevicemotion = null;
get_ipad_version();
}
@benhuson
benhuson / users2csv.php.patch
Last active December 31, 2015 20:39
Patch for Users 2 CSV WordPress plugin.
Index: users2csv.php
===================================================================
--- users2csv.php (revision 277117)
+++ users2csv.php (working copy)
@@ -26,7 +26,7 @@
if ( is_admin() ) {
- if ($_GET['page'] == "users2csv.php") {
+ if ( isset( $_GET['page'] ) && $_GET['page'] == 'users2csv.php' ) {
@benhuson
benhuson / custom-posts-order
Last active December 25, 2015 21:09
WordPress custom order for main query
<?php
/**
* Post Order
*/
function product_orderby( $query ) {
if ( $query->is_main_query() && ( is_post_type_archive( 'custom_post_type_name' ) ) ) {
$query->set( 'order', 'ASC' );
$query->set( 'orderby','menu_order' );
}
@benhuson
benhuson / js-clickable-block.js
Created May 29, 2013 08:35
JS Clickable Block
jQuery(".clickable-block").click(function(){
window.location = jQuery(this).find('a').attr('href');
return false;
});
@benhuson
benhuson / multiple-post-thumbnails.php
Created May 13, 2013 10:29
WordPress Multiple Post Thumbnails plugin setup. Example of setting up a background image option.
/**
* Multiple Post Thumbnails (plugin compatibility)
* http://wordpress.org/extend/plugins/multiple-post-thumbnails/
*/
if ( class_exists( 'MultiPostThumbnails' ) ) {
$types = array( 'page' );
foreach ( $types as $type ) {
new MultiPostThumbnails( array(
'label' => _x( 'Background Image', 'admin', 'mytheme' ),
'id' => 'background-image',
@benhuson
benhuson / users2csv.php.patch
Created April 4, 2013 21:47
Patch for the Users 2 CSV WordPress plugin. Change the first column heading to UID rather than duplicate URL title. Fixes some PHP warnings for variables.
Index: users2csv.php
===================================================================
--- users2csv.php (revision 277117)
+++ users2csv.php (working copy)
@@ -26,7 +26,7 @@
if ( is_admin() ) {
- if ($_GET['page'] == "users2csv.php") {
+ if ( isset( $_GET['page'] ) && $_GET['page'] == 'users2csv.php' ) {
@benhuson
benhuson / hide-tiff-thumbnails
Created March 11, 2013 13:22
Hide Tiff thumbnails in WordPress admin. Useful for when dealing with large TIFF files, thumbnail aren't created so it tries to load tiff image into media library.
/**
* Don't try to show TIFF thumbnails in admin
*/
function my_wp_prepare_attachment_for_js( $response, $attachment, $meta ) {
if ( is_admin() && $response['type'] == 'image' && in_array( $response['subtype'], array( 'tiff', 'tif' ) ) ) {
$response['type'] = 'application';
}
return $response;
}
add_filter( 'wp_prepare_attachment_for_js', 'my_wp_prepare_attachment_for_js', 10, 3 );
@benhuson
benhuson / gist:4659950
Created January 28, 2013 22:35
Setup canonical links for WPEC products in multiple categories.
<?php
/**
* Fix canonical for posts in multiple categories
*/
class CanonicalCategoryFix {
function CanonicalCategoryFix() {
add_filter( 'wpseo_canonical', array( $this, 'canonical_permalink' ) );
add_filter( 'wpsc_change_canonical_url', array( $this, 'canonical_permalink' ) );