Skip to content

Instantly share code, notes, and snippets.

Avatar

Andrea Whitmer nutsandbolts

View GitHub Profile
@nutsandbolts
nutsandbolts / Move comment box (add to functions.php)
Created Nov 19, 2013
Move comment box above the comments list (Genesis)
View Move comment box (add to functions.php)
add_action( 'genesis_before_comments' , 'nabm_post_check' );
function nabm_post_check () {
if ( is_single() ) {
if ( have_comments() ) {
remove_action( 'genesis_comment_form', 'genesis_do_comment_form' );
add_action( 'genesis_list_comments', 'genesis_do_comment_form' , 5 );
}
}
}
@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 / (Force excerpts on Genesis search results (functons.php)
Last active Jan 9, 2019 — forked from srikat/functions.php
Forces Genesis search results to display excerpts no matter what options are chosen in the theme archive settings. Props to @srikat for this one!
View (Force excerpts on Genesis search results (functons.php)
add_action( 'genesis_before_loop', 'sk_excerpts_search_page' );
function sk_excerpts_search_page() {
if ( is_search() ) {
add_filter( 'genesis_pre_get_option_content_archive', 'sk_show_excerpts' );
}
}
function sk_show_excerpts() {
return 'excerpts';
}
@nutsandbolts
nutsandbolts / Force content-sidebar layout on blog (Genesis)
Last active Jul 24, 2018
Force content-sidebar layout on blog posts when your default layout is full-width content
View Force content-sidebar layout on blog (Genesis)
//* Force sidebar on blog posts and archives
add_filter( 'genesis_pre_get_option_site_layout', 'nabm_force_layout' );
function nabm_force_layout( $opt ) {
if ( is_single() || is_archive() ) {
$opt = 'content-sidebar';
return $opt;
}
}
@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;
}
View XHTML Conditional to display widget area on page
//* Add the page widget in the content - XHTML
add_action( 'genesis_after_post_content', 'nabm_add_page_content' );
function nabm_add_page_content() {
if ( is_page('ID') )
genesis_widget_area ('page-widget', array(
'before' => '<div class="page-widget"><div class="wrap">',
'after' => '</div></div>',
) );
}
View Register the page widget area in functions.php
genesis_register_sidebar( array(
'id' => 'page-widget',
'name' => __( 'Page Widget', 'nabm' ),
'description' => __( 'This is the widget area for a specific page.', 'nabm' ),
) );
View HTML5 Conditional to display widget area on page
//* Add the page widget in the content - HTML5
add_action( 'genesis_entry_footer', 'nabm_add_page_content' );
function nabm_add_page_content() {
if ( is_page('ID') )
genesis_widget_area ('page-widget', array(
'before' => '<div class="page-widget"><div class="wrap">',
'after' => '</div></div>',
) );
}
@nutsandbolts
nutsandbolts / Base CSS for widget on page
Last active Apr 11, 2017
Add a widget area to a page using the Genesis Framework
View Base CSS for widget on page
/* Page Widget
------------------------------------------------------------ */
.page-widget {
line-height: 1.5;
padding: 30px;
}
.page-widget p {
margin-bottom: 24px;
@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;
}