Skip to content

Instantly share code, notes, and snippets.

View nutsandbolts's full-sized avatar

Andrea Whitmer nutsandbolts

View GitHub Profile
@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;
@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 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
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
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 / 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 / gist:8f0bea7a91a6c270c731
Last active August 29, 2015 14:02
Header for custom functionality plugin
<?php
/*
Plugin Name: Nuts and Bolts Theme Functions
Plugin URI: http://www.nutsandboltsmedia.com
Description: Custom Genesis functions for the Nuts and Bolts Media website.
Version: 2.0
Author: Nuts and Bolts Media, LLC
Author URI: http://www.nutsandboltsmedia.com/
This plugin is released under the GPLv2 license. The images packaged with this plugin are the property of
@nutsandbolts
nutsandbolts / gist:1b7b080a4a4185bba23f
Created June 6, 2014 00:05
Footer script to open all comment links in a new tab (goes in Genesis theme settings > footer scripts box)
<script type="text/javascript" src="http://code.jquery.com/jquery-latest.min.js"></script>
<script type="text/javascript">
$(window).ready(function(){
//adds target blank to all comment links
$('#comments a').each(function(){
$(this).attr('target','_blank');
});
});
</script>
@nutsandbolts
nutsandbolts / gist:704c2c3ac9e64cc28a6b
Created June 4, 2014 16:03
Move secondary nav to footer
//* Reposition secondary navigation
remove_action( 'genesis_after_header', 'genesis_do_subnav' );
add_action( 'genesis_footer', 'genesis_do_subnav' );
@nutsandbolts
nutsandbolts / Button shortcode
Created January 19, 2014 02:31
Create a button shortcode to be used in the page/post editor (goes in functions.php)
//* Add shortcode for buttons
function nabm_button_shortcode( $atts, $content = 'Click Here' ) {
extract(shortcode_atts(array(
'url' => '#'
'target' => '',
), $atts));
$target = ($target == 'blank') ? ' target="_blank"' : '';
$button = '<a target=" 'esc_attr( $target ). '" class="button" href="' . esc_url( $url ) . '">' . esc_attr( $content ) . '</a>';
return $button;
}