Skip to content

Instantly share code, notes, and snippets.

View gthayer's full-sized avatar

Gary Thayer gthayer

View GitHub Profile
@EvanHerman
EvanHerman / redirect-user-back-to-product.php
Created November 13, 2015 16:30
WooCommerce - After login, redirect the user back to the last viewed product
<?php
/*
* Add a hidden field to our WooCommerce login form - passing in the refering page URL
* Note: the input (hidden) field doesn't actually get created unless the user was directed
* to this page from a single product page
*/
function redirect_user_back_to_product() {
// check for a referer
$referer = wp_get_referer();
// if there was a referer..
@jlavoie13
jlavoie13 / tmpl-sitemap.php
Last active August 29, 2015 14:13
Site Map Template
<?php
/**
* Template Name: Site Map Page
*
* @package Scaffolding
* @since Scaffolding 1.1
*/
get_header();
@jlavoie13
jlavoie13 / template-h1-tag.php
Last active December 16, 2015 18:07
Tuckaway H1
<?php
/**
* H1 Tag Template
*
* This is a tuckaway H1 tag for SEO purposes.
*/
// Set Variables
$h1_field = 'h1_tag'; // the field name defined in acf
$default_posttype = 'News'; // ex. Posts or News
@TimBHowe
TimBHowe / function.php
Created November 20, 2013 17:27
Redirect non admin users to the home page after logging in. - Original Source (http://tommcfarlin.com/redirect-non-admin/)
// Redirect non-admins to the homepage after logging into the site.
function nonadmin_login_redirect( $redirect_to, $request, $user ) {
return ( is_array( $user->roles ) && in_array( 'administrator', $user->roles ) ) ? admin_url() : site_url();
}
add_filter( 'login_redirect', 'nonadmin_login_redirect', 10, 3 );
@TimBHowe
TimBHowe / gist:6765309
Created September 30, 2013 15:16
PHP function to truncate a string up to a number of characters while preserving whole words and HTML tags. Source from http://alanwhipple.com/2011/05/25/php-truncate-string-preserving-html-tags-words/
<?php
/**
* truncateHtml can truncate a string up to a number of characters while preserving whole words and HTML tags
*
* @param string $text String to truncate.
* @param integer $length Length of returned string, including ellipsis.
* @param string $ending Ending to be appended to the trimmed string.
* @param boolean $exact If false, $text will not be cut mid-word
* @param boolean $considerHtml If true, HTML tags would be handled correctly
*