Skip to content

Instantly share code, notes, and snippets.

Andrea Whitmer nutsandbolts

Block or report user

Report or block nutsandbolts

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@nutsandbolts
nutsandbolts / functions.php
Last active Sep 10, 2015
Daily Bolt: increase posts per page
View functions.php
//* 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 Apr 15, 2015
Daily Bolt: open entry title links in a new tab
View functions.php
//* 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 Nov 9, 2017
Daily Bolt: redirect single posts to articles
View functions.php
//* 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 Jan 22, 2019
Calculate and display number of views in Genesis post meta
View functions.php
//* 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 Mar 28, 2015
Add login/logout link to Genesis nav
View functions.php
//* 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 Aug 29, 2015
Files for Video CPT Tutorial
View archive-videos.php
<?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 Aug 29, 2015
Header for custom functionality plugin
View gist:8f0bea7a91a6c270c731
<?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 Jun 6, 2014
Footer script to open all comment links in a new tab (goes in Genesis theme settings > footer scripts box)
View gist:1b7b080a4a4185bba23f
<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 Jun 4, 2014
Move secondary nav to footer
View gist:704c2c3ac9e64cc28a6b
//* Reposition secondary navigation
remove_action( 'genesis_after_header', 'genesis_do_subnav' );
add_action( 'genesis_footer', 'genesis_do_subnav' );
@nutsandbolts
nutsandbolts / Button shortcode
Created Jan 19, 2014
Create a button shortcode to be used in the page/post editor (goes in functions.php)
View Button shortcode
//* 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;
}
You can’t perform that action at this time.