Skip to content

Instantly share code, notes, and snippets.

View blogjunkie's full-sized avatar

David Wang blogjunkie

View GitHub Profile
@blogjunkie
blogjunkie / gist:4712311
Last active April 2, 2016 05:57
Display a custom message for WooCommerce subscription products in order complete email. Goes in your theme's functions.php or as a plugin. Credits: Patrick Garman (@pmgarman)
<?php
/* Custom message for subscription products in order complete email */
add_action( 'woocommerce_email_after_order_table', 'wc_completed_email_snippet' );
function wc_completed_email_snippet( $order ) {
$order_statuses = array( 'completed' ); // order statuses to enable the email on
$display_cats = array( 148, 149 ); // cat ID's of products to display the message on completed emails for
if( in_array( $order->status, $order_statuses ) )
return; // only completed orders
if( !class_exists( 'WC_Subscriptions_Order' ) || !class_exists( 'WC_Subscriptions_Renewal_Order' ) )
@blogjunkie
blogjunkie / taxonomies.php
Created February 26, 2013 02:25
Register custom taxonomies 1) quote topic and 2) quote author for quote custom post type
<?php
/**
* Taxonomies
*
* This file registers any custom taxonomies
*
* @package Core_Functionality
* @since 1.0.0
* @link https://github.com/billerickson/Core-Functionality
* @author Bill Erickson <bill@billerickson.net>
@blogjunkie
blogjunkie / child-theme-settings.php
Last active May 27, 2018 13:45
Integrate the WordPress Media Uploader in Theme Options. Reference this function from your add_meta_box() callback
<?php
function upload_image_metabox() {
echo '<p><strong>Upload image</strong></p>';
echo '<input type="text" id="child_logo_url" name="' . $this->get_field_name( 'welcome-image' ) . '" value="' . esc_attr( $this->get_field_value( 'welcome-image' ) ) . '" size="50" />';
echo '<input id="child_upload_logo_button" type="button" class="button" value="Upload Image" /> ';
?>
@blogjunkie
blogjunkie / functions.php
Created June 24, 2014 03:55
Remove WooCommerce Generator tag, styles, and scripts from non WooCommerce pages
<?php
/**
* Optimize WooCommerce Scripts
* Remove WooCommerce Generator tag, styles, and scripts from non WooCommerce pages.
*
* @link http://wordimpress.com/how-to-load-woocommerce-scripts-and-styles-only-in-shop/
*/
add_action( 'wp_enqueue_scripts', 'child_manage_woocommerce_styles', 99 );
@blogjunkie
blogjunkie / functions.php
Last active August 29, 2015 14:03
Add permalink to genesis [post_date] shortcode
<?php
/**
* Customize post meta.
*
* @since 3.0
*/
//* Customize the post meta function
add_filter( 'genesis_post_meta', 'child_post_meta_filter' );
@blogjunkie
blogjunkie / gist:2b91b095efe9a6212787
Created July 16, 2014 16:07
Get array of post IDs
<?php
$featured_posts = get_posts(
array(
'posts_per_page' => 5,
'tax_query' => array(
array(
'taxonomy' => 'post_tag',
'field' => 'slug',
'terms' => 'featured',
@blogjunkie
blogjunkie / template-page-builder.php
Last active May 11, 2016 13:28
A custom page template for #GenesisWP to play nice with page builders by making the content area full width. Works great with the Beaver Builder http://clickwp.me/beaver
<?php
/**
* Template Name: Page Builder
*
* This page template only works with Genesis child themes and works great with the
* Beaver Builder plugin. Learn more: http://clickwp.com/blog/beaver-builder/
*/
// Force full width content layout to remove sidebar
@blogjunkie
blogjunkie / gist:f4a66c30a8d92d682609
Created November 4, 2014 04:58
Open external links in new window with jQuery
<!-- open external links in new window -->
<script type="text/javascript">
jQuery(document).ready(function($) {
$('div.entry-content a, aside.sidebar a').each(function() {
var a = new RegExp('/' + window.location.host + '/');
if(!a.test(this.href)) {
$(this).click(function(event) {
event.preventDefault();
event.stopPropagation();
window.open(this.href, '_blank');
@blogjunkie
blogjunkie / functions.php
Last active March 16, 2019 01:06
Custom page titles for co-authors with WordPress SEO
<?php
/**
* Custom page titles for Guest Authors with WordPress SEO
* Returns "[author name]&#39;s articles on [site name]"
*
*/
add_filter('wpseo_title', 'my_co_author_wseo_title');
function my_co_author_wseo_title( $title ) {
@blogjunkie
blogjunkie / front-page.php
Last active August 30, 2015 03:10
Cache Metro Pro homepage with Transients API
<?php
//* Do NOT include the opening php tag shown above. Only modified code shown below.
function metro_homepage_widgets() {
// get the transient
$metro_homepage_content = get_transient( 'metro_homepage_content' );
// check if homepage content exists
if ( false === $metro_homepage_content ) :