Skip to content

Instantly share code, notes, and snippets.

View GaryJones's full-sized avatar

Gary Jones GaryJones

View GitHub Profile
@GaryJones
GaryJones / gist:1258784
Created October 3, 2011 09:37 — forked from jaredatch/gist:1256954
Using the template_include filter in WordPress
<?php
add_filter( 'template_include', 'ja_template_include' );
/**
* Apply a template to all subcategories of a certain parent category.
*
* @author Jared Atchison
* @link http://www.jaredatchison.com/2011/10/02/taking-advantage-of-the-template_include-filter/
*
* @param string $template Existing path to template file
* @return string Potentially amended path to template file
@GaryJones
GaryJones / nav-extras.php
Last active April 30, 2020 15:14 — forked from studiopress/nav-extras.php
Add Genesis Primary Nav Extras features in manually.
<?php
// Don't include the above <?php when copying
add_filter( 'wp_nav_menu_items', 'prefix_primary_nav_extras', 10, 2 );
/**
* Filter menu items, appending either a search form or today's date.
*
* @param string $menu HTML string of list items.
* @param stdClass $args Menu arguments.
<?php
// Create color style options
add_theme_support( 'genesis-style-selector', array(
'theme-blue' => __( 'Blue', 'your-child-theme-text-domain' ),
'theme-green' => __( 'Green', 'your-child-theme-text-domain' ),
'theme-orange' => __( 'Orange', 'your-child-theme-text-domain' ),
'theme-red' => __( 'Red', 'your-child-theme-text-domain' ),
) );
<?php
/**
* Add Extra Code to Any Menu
* @author Bill Erickson
* @link http://www.billerickson.net/customizing-wordpress-menus/
*
* @param string $menu
* @param object $args
* @return string modified menu
*/
<?php
/**
* Get post image.
*/
function wds_get_post_image( $size = 'thumbnail' ) {
// If featured image is present, use that
if ( has_post_thumbnail() ) {
return get_the_post_thumbnail( $size );
@GaryJones
GaryJones / gist:daaa55c4c4b380ecfb70
Created January 22, 2016 10:08 — forked from srikat/gist:8350989
Conditional code for different days of a week
<?php
$dates = array("Sunday",
"Monday",
"Tuesday",
"Wednesday",
"Thursday",
"Friday",
"Saturday"
);
@GaryJones
GaryJones / gist:2437195
Created April 21, 2012 13:55 — forked from miklb/gist:2437076
WordPress redirect single search result
<?php
add_action( 'template_redirect', 'kkf_single_search_redirect' );
/**
* If only one search result match, automatically redirect to that result.
*
* @author Michael Bishop
* @link https://gist.github.com/2437076
*
* @global WP_Query $wp_query Query object.
@GaryJones
GaryJones / gravity-au.php
Last active April 27, 2016 15:54 — forked from thewebprincess/gravity-au.php
Australian address format for Gravity Forms.
<?php
add_filter( 'gform_address_types', 'your_plugin_slug_australian_address' );
/**
* Set Gravity Forms custom addresses for Australia.
*
* @since 1.0.0
*
* @param array $address_types Existing address formats.
* @param int $form_id Form ID.
@GaryJones
GaryJones / gist:7183071
Last active December 26, 2015 16:49 — forked from salcode/gist:7164690
<?php
/*
* Examples to add custom classes to Genesis WordPress Framework Markup when using HTML5 output
*/
add_action( 'genesis_setup', 'srf_add_cust_classes', 15 ); // Priority 15 ensures it runs after Genesis itself has setup.
function srf_add_cust_classes() {
add_filter( 'genesis_attr_site-inner', 'srf_attr_site_inner' );
add_filter( 'genesis_attr_content-sidebar-wrap', 'srf_attr_content_sidebar_wrap' );
add_filter( 'genesis_attr_content', 'srf_attr_content' );
add_filter( 'genesis_attr_sidebar-primary', 'srf_attr_sidebar_primary' );
<?php
//* Do NOT include the opening php tag
//* Add Organization schema to our logo
add_filter( 'genesis_seo_title', 'rvam_header_title', 10, 3 );
function rvam_header_title( $title, $inside, $wrap ) {
$inside = sprintf( '<div itemscope="itemscope" itemtype="http://schema.org/Organization"><a itemprop="url" href="%s" title="%s"><img class="logo" itemprop="logo" src="http://www.rvamedia.com/img/rva-media.png" alt="%s" /></a></div>', trailingslashit( home_url() ), esc_attr( get_bloginfo( 'name' ) ), get_bloginfo( 'name' ) );
return sprintf( '<%1$s id="title">%2$s</%1$s>', 'span', $inside );
}