Skip to content

Instantly share code, notes, and snippets.

View blogjunkie's full-sized avatar

David Wang blogjunkie

View GitHub Profile
@blogjunkie
blogjunkie / functions.php
Created August 5, 2015 07:33
Make WooCommerce product archive obey shop page layout settings
/**
* Make WooCommerce product archive obey shop page layout settings
*/
add_filter( 'genesis_pre_get_option_site_layout', 'vh_do_shop_layout' );
function vh_do_shop_layout( $opt ) {
if ( is_post_type_archive('product') ) {
$opt = get_post_meta( wc_get_page_id('shop'), '_genesis_layout', true);
return $opt;
}
}
@blogjunkie
blogjunkie / 0_reuse_code.js
Last active August 29, 2015 14:25
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@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 ) :
@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 / 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 / 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: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 / 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 / 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 / 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" /> ';
?>