Skip to content

Instantly share code, notes, and snippets.

View blogjunkie's full-sized avatar

David Wang blogjunkie

View GitHub Profile
@blogjunkie
blogjunkie / screen.js
Created August 28, 2015 09:02
Open external links in new window
/**
* Open all external links in a new window
*/
jQuery(document).ready(function($) {
$('a').not('[href*="mailto:"]').each(function () {
var isInternalLink = new RegExp('/' + window.location.host + '/');
if ( ! isInternalLink.test(this.href) ) {
$(this).attr('target', '_blank');
}
});
@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 / 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 / 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 / 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 / functions.php
Created August 5, 2015 07:33
Adding support for WooCommerce in Genesis via Stéphane Bergeron. "I'm using a modified version of this: http://joshmallard.com/2013/09/23/woocommerce-genesis-2-0/ The way I modified it is that, I don't put anything in functions.php other than the add_theme_support( 'woocommerce' ); line. Instead I replace what Josh has in his woocommerce.php tem…
// Declare WooCommerce support for your theme
add_theme_support( 'woocommerce' );
@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 / style.css
Last active August 31, 2015 09:04
Better default styling for Related Posts for WP plugin. Replace the default CSS in the Settings → Related Posts → Styling tab.
.rp4wp-related-posts:after,
.rp4wp-related-posts ul:after {
clear: both;
content: "";
display: table;
}
.rp4wp-related-posts > ul {
margin-left: 0;
padding-left: 0;