Skip to content

Instantly share code, notes, and snippets.

View braddalton's full-sized avatar

Brad Dalton braddalton

View GitHub Profile
@braddalton
braddalton / gist:4741976
Last active March 7, 2017 18:08
Add Widget Before Content On Single Page In Genesis Using Conditional Tag
// Register before-content widget
genesis_register_sidebar( array(
'id' => 'before-content',
'name' => __( 'Before Content', 'agency' ),
'description' => __( 'This is the before-content section.', 'agency' ),
) );
// Hook before-post widget to single page
add_action( 'genesis_before_content_sidebar_wrap', 'custom_before_content', 9 );
function custom_before_content() {
@braddalton
braddalton / Menu Item Descriptions
Last active December 13, 2015 20:39
Add Menu Item Descriptions
class Menu_With_Description extends Walker_Nav_Menu {
function start_el(&$output, $item, $depth, $args) {
global $wp_query;
$indent = ( $depth ) ? str_repeat( "\t", $depth ) : '';
$class_names = $value = '';
$classes = empty( $item->classes ) ? array() : (array) $item->classes;
$class_names = join( ' ', apply_filters( 'nav_menu_css_class', array_filter( $classes ), $item ) );
$class_names = ' class="' . esc_attr( $class_names ) . '"';
@braddalton
braddalton / Add html home page genesis hooks
Created February 23, 2013 21:25
Place code for HTML image or text in any theme location using Genesis Simple Hooks plugin and conditional tags
<?php if (is_home() ) { ?><p>Insert-HTML-Code-Here</p><?php } ?>
@braddalton
braddalton / Custom Genesis Loop.php
Last active December 14, 2015 03:29
Custom Genesis blog page loop with exclude posts from one category
<?php /*
Template Name: Exclude Categories
*/
/** Custom Genesis loop */
remove_action( 'genesis_loop', 'genesis_do_loop' );
add_action( 'genesis_loop', 'child_do_custom_loop' );
function child_do_custom_loop() {
@braddalton
braddalton / functions.php
Last active August 15, 2017 00:07
Exclude posts from one or more categories from displaying on your home page http://wpsites.net/web-design/exclude-category-posts-page/
add_action( 'pre_get_posts', 'exclude_category_posts' );
/**
* @author Brad Dalton - WP Sites
* @example http://wpsites.net/web-design/exclude-category-posts-page/
*/
function exclude_category_posts( $query ) {
if( $query->is_main_query() && $query->is_home() ) {
$query->set( 'cat', array( -27, -30 ) );
}
}
@braddalton
braddalton / Remove Specific Category Posts.php
Last active December 14, 2015 03:29
Add code to themes hooks plugin or index.php to remove posts from one or more categories from displaying on the home page
//Code for one category
<?php if ( is_home() ) { query_posts( 'cat=-1' ); } ?>
//Code for multiple categories
<?php if ( is_home() ) { query_posts( 'cat=-1,-2,-3' ); } ?>
/**
* @author Brad Dalton - WP Sites
* @example http://wp.me/p1lTu0-9OJ
*/
// Change conditional tag to remove posts from displaying on blog or other pages
@braddalton
braddalton / Delete Native Widgets from WordPress
Created February 24, 2013 05:29
This code removes all the default widgets from WordPress. You can also modify this code to keep the default widgets you want to use and delete the remainder.
function unregister_widgets() {
unregister_widget('WP_Widget_Pages');
unregister_widget('WP_Widget_Calendar');
unregister_widget('WP_Widget_Archives');
unregister_widget('WP_Widget_Meta');
unregister_widget('WP_Widget_Search');
unregister_widget('WP_Widget_Text');
unregister_widget('WP_Widget_Categories');
unregister_widget('WP_Widget_Recent_Posts');
unregister_widget('WP_Widget_Recent_Comments');
@braddalton
braddalton / Remove All Widgets Home Page
Created February 24, 2013 12:52
This code removes all your widgets from all widget areas on your home page. You can change the conditional tag to disable widgets from loading on specific pages etc.
add_filter( 'sidebars_widgets', 'remove_homepage_widgets' );
function remove_homepage_widgets( $sidebars_widgets ) {
if ( is_home() )
$sidebars_widgets = array( false );
return $sidebars_widgets;
}
@braddalton
braddalton / Remove All Widgets Specific Page
Created February 24, 2013 12:54
Prevents widgets from loading on a specific page. Change the page i.d or conditional tag.
add_filter ('sidebars_widgets', 'remove_specific_pages_widget');
function remove_specific_pages_widget( $sidebars_widgets ){
if (is_page('007'))
$sidebars_widgets ['sidebar'] = false;
return $sidebars_widgets;
}
@braddalton
braddalton / Remove All Default WordPress Widgets
Created February 24, 2013 12:56
This code removes all the current default widgets from loading and can be modified to your own needs.
function remove_wordpress_widgets() {
unregister_widget('WP_Widget_Pages');
unregister_widget('WP_Widget_Calendar');
unregister_widget('WP_Widget_Archives');
unregister_widget('WP_Widget_Meta');
unregister_widget('WP_Widget_Search');
unregister_widget('WP_Widget_Text');
unregister_widget('WP_Widget_Categories');
unregister_widget('WP_Widget_Recent_Posts');
unregister_widget('WP_Widget_Recent_Comments');