Skip to content

Instantly share code, notes, and snippets.

View nutsandbolts's full-sized avatar

Andrea Whitmer nutsandbolts

View GitHub Profile
@nutsandbolts
nutsandbolts / archive-videos.php
Last active August 29, 2015 14:08
Files for Video CPT Tutorial
<?php
/**
* This file adds the custom video post type archive template to a Genesis child theme.
*
*/
//* Load Isotope
wp_enqueue_script('isotope', get_stylesheet_directory_uri() . '/js/jquery.isotope.min.js', array('jquery'), '', true);
wp_enqueue_script('isotope_init', get_stylesheet_directory_uri() . '/js/isotope_init.js', array('isotope'), '1.0.0', true);
@nutsandbolts
nutsandbolts / functions.php
Created March 28, 2015 06:08
Add login/logout link to Genesis nav
//* Add login or logout to menu
add_filter( 'wp_nav_menu_items', 'sp_add_loginout_link', 10, 2 );
function sp_add_loginout_link( $items, $args ) {
// Change 'primary' to 'secondary' to put the login link in your secondary nav bar
if ( $args->theme_location != 'primary' )
return $items;
if ( is_user_logged_in() ) {
$items .= '<li class="menu-item right"><a href="'. wp_logout_url() .'">Log Out</a></li>';
} else {
@nutsandbolts
nutsandbolts / functions.php
Last active January 22, 2019 15:06
Calculate and display number of views in Genesis post meta
//* Get post view counts
function getPostViews($postID){
$count_key = 'post_views_count';
$count = get_post_meta($postID, $count_key, true);
if($count==''){
delete_post_meta($postID, $count_key);
add_post_meta($postID, $count_key, '0');
return "0 Views";
}
return $count.' Views';
@nutsandbolts
nutsandbolts / functions.php
Last active November 9, 2017 06:14
Daily Bolt: redirect single posts to articles
//* Redirect posts to original URL
add_action( 'template_redirect', 'nabm_original_post_redirect' );
function nabm_original_post_redirect() {
if ( ! is_singular() ) {
return;
}
if ( $url = genesis_get_custom_field( 'rss_pi_source_url' ) ) {
wp_redirect( esc_url_raw( $url ), 301 );
exit;
}
@nutsandbolts
nutsandbolts / functions.php
Created April 15, 2015 03:43
Daily Bolt: open entry title links in a new tab
//* Open post title links in new tab
function nabm_filter_entry_title() {
function nabm_post_title_output( $title ) {
$title = sprintf( '<h1 class="entry-title" itemprop="headline"><a target="_blank" href="%s" title="%s">%s</a></h1>', get_permalink(), the_title_attribute( 'echo=0' ), get_the_title() );
return $title;
}
add_filter( 'genesis_post_title_output', 'nabm_post_title_output', 15 );
}
add_action('genesis_header', 'nabm_filter_entry_title');
@nutsandbolts
nutsandbolts / functions.php
Last active September 10, 2015 04:01
Daily Bolt: increase posts per page
//* Show 12 posts per page
add_action( 'pre_get_posts', 'nabm_change_posts_per_page' );
function nabm_change_posts_per_page( $query ) {
if ( ! $query->is_main_query() || is_admin() || is_feed() ) {
return $query;
}
if ( is_front_page() ) {
$query->set( 'posts_per_page', 12 );
}
return $query;