Skip to content

Instantly share code, notes, and snippets.

View nutsandbolts's full-sized avatar

Andrea Whitmer nutsandbolts

View GitHub Profile
@nutsandbolts
nutsandbolts / Move comment box (add to functions.php)
Created November 19, 2013 01:49
Move comment box above the comments list (Genesis)
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 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 / (Force excerpts on Genesis search results (functons.php)
Last active January 9, 2019 20:06 — 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!
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 July 24, 2018 16:04
Force content-sidebar layout on blog posts when your default layout is full-width content
//* 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 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 / XHTML Conditional to display widget area on page
Last active April 26, 2017 18:20
Add a widget area to a Genesis 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>',
) );
}
@nutsandbolts
nutsandbolts / Register the page widget area in functions.php
Last active April 11, 2017 17:40
Add widget area to a Genesis page
genesis_register_sidebar( array(
'id' => 'page-widget',
'name' => __( 'Page Widget', 'nabm' ),
'description' => __( 'This is the widget area for a specific page.', 'nabm' ),
) );
@nutsandbolts
nutsandbolts / HTML5 Conditional to display widget area on page
Last active April 11, 2017 17:40
Add a widget area to a Genesis 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 April 11, 2017 17:40
Add a widget area to a page using the Genesis Framework
/* Page Widget
------------------------------------------------------------ */
.page-widget {
line-height: 1.5;
padding: 30px;
}
.page-widget p {
margin-bottom: 24px;
@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;
}