Skip to content

Instantly share code, notes, and snippets.

View craigsimps's full-sized avatar

Craig Simpson craigsimps

View GitHub Profile
function customize_cpt_archive_query( $query ) {
if ( is_post_type_archive( 'gemstone' ) ) {
$query->set( 'posts_per_page', -1 );
$query->set( 'orderby', 'title' );
$query->set( 'order', 'ASC' );
return;
}
}
add_action( 'pre_get_posts', 'customize_cpt_archive_query', 1 );
@craigsimps
craigsimps / functions.php
Last active August 29, 2015 14:25
Add a link to BrowseHappy to the header of your Genesis Child theme if the visitor is using Internet Explorer 8 or below.
add_action( 'genesis_before', 'craigsimps_browsehappy' );
/**
* Show the browsehappy link
* if browser is less than IE8
*/
function craigsimps_browsehappy() {
?>
<!--[if lt IE 8]>
<p class="browserupgrade">You are using an <strong>outdated</strong> browser. Please <a href="http://browsehappy.com/">upgrade your browser</a> to improve your experience.</p>
<![endif]-->
.browserupgrade {
background: #ccc;
color: #000;
padding: 10px 0;
text-align: center;
}
@craigsimps
craigsimps / functions.php
Last active August 29, 2015 14:25
Add the Modernizr JS library for Internet Explorer 8 users and below.
// remove the existing loading of html5shiv
remove_action( 'wp_head', 'genesis_html5_ie_fix' );
add_action( 'wp_enqueue_scripts', 'craigsimps_enqueue_modernizr' );
/**
* Load the modernizr library, with built in html5shiv for users of IE8 or below.
*/
function craigsimps_enqueue_modernizr() {
global $wp_scripts;
wp_enqueue_script( 'craigsimps-modernizr', get_stylesheet_directory_uri() . '/assets/js/modernizr.min.js', array('jquery'), '2.8.3', true );
@craigsimps
craigsimps / functions.php
Created August 11, 2015 15:04
Insert content after a defined number of paragraphs.
<?php
//Insert ads after second paragraph of single post content.
add_filter( 'the_content', 'prefix_insert_post_ads' );
function prefix_insert_post_ads( $content ) {
$ad_code = '<div>Ads code goes here</div>';
@craigsimps
craigsimps / functions.php
Last active August 29, 2015 14:27
Remove the screen reader text class from the search form. Genesis 2.2.
<?php
add_filter( 'genesis_search_form', 'prefix_unhide_search_label' );
function prefix_unhide_search_label( $markup ) {
return str_replace( ' screen-reader-text', '', $markup );
}
@craigsimps
craigsimps / functions.php
Created August 15, 2015 10:32
By default, get_field will often return an array of post objects. If you try to access this using get_post_meta, you will see only an array of post ids. This function allows you to input the field name, and returns an array of post objects.
<?php
function return_array_of_objects_from_acf_ids( $field_name ) {
$post_ids = get_post_meta( get_the_ID(), $field_name, true );
foreach ( $post_ids as $post_id ) {
$objects[] = get_post( $post_id );
}
@craigsimps
craigsimps / functions.php
Created August 19, 2015 13:00
Return an array of ACF fields.
<?php
function get_acf_meta( $post_id, array $meta_keys ) {
foreach ( $meta_keys as $meta_key ) {
$fields[$meta_key] = get_post_meta( $post_id, $meta_key, true );
}
return $fields;
@craigsimps
craigsimps / functions.php
Created September 14, 2015 08:19
Remove links from post titles in Genesis.
<?php
add_filter( 'genesis_post_title_output', 'genesis_starter_custom_post_title' );
/**
*
* Remove Links from Post Titles in Genesis
*
* @author Joshua Nelson
* @link http://joshuadnelson.com
*
@craigsimps
craigsimps / functions.php
Created December 14, 2015 14:39
Simple function to determine if a date is in the future.
/**
*
* Simple function to determine if a date is in the future.
*
* @param $time
*
* @return bool
*/
function isFuture($time)
{