Skip to content

Instantly share code, notes, and snippets.

Avatar

Brad Dalton braddalton

View GitHub Profile
@braddalton
braddalton / gist:4741976
Last active Mar 7, 2017
Add Widget Before Content On Single Page In Genesis Using Conditional Tag
View gist:4741976
// 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 Dec 13, 2015
Add Menu Item Descriptions
View 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 Feb 23, 2013
Place code for HTML image or text in any theme location using Genesis Simple Hooks plugin and conditional tags
View Add html home page genesis hooks
<?php if (is_home() ) { ?><p>Insert-HTML-Code-Here</p><?php } ?>
@braddalton
braddalton / Custom Genesis Loop.php
Last active Dec 14, 2015
Custom Genesis blog page loop with exclude posts from one category
View Custom Genesis Loop.php
<?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 Aug 15, 2017
Exclude posts from one or more categories from displaying on your home page http://wpsites.net/web-design/exclude-category-posts-page/
View functions.php
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 Dec 14, 2015
Add code to themes hooks plugin or index.php to remove posts from one or more categories from displaying on the home page
View Remove Specific Category Posts.php
//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 Feb 24, 2013
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.
View Delete Native Widgets from WordPress
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 Feb 24, 2013
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.
View Remove All Widgets Home Page
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 Feb 24, 2013
Prevents widgets from loading on a specific page. Change the page i.d or conditional tag.
View Remove All Widgets Specific Page
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 Feb 24, 2013
This code removes all the current default widgets from loading and can be modified to your own needs.
View Remove All Default WordPress Widgets
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');