Skip to content

Instantly share code, notes, and snippets.

View braddalton's full-sized avatar

Brad Dalton braddalton

View GitHub Profile
@braddalton
braddalton / functions.php
Last active December 14, 2015 18:09
Add one or more category i.d's to this code which will exclude all posts assigned to that category from displaying in your RSS feed. http://wpsites.net/wordpress-tips/exclude-categories-rss-feed/
function wpsites_exclude_category_feed($query) {
if ($query->is_feed) {
$query->set('cat','-007');
}
return $query;
}
/**
* @author Brad Dalton
* @example http://wpsites.net/
* @copyright 2014 WP Sites
@braddalton
braddalton / Centre Post Image & Add Margin Before Title.css
Last active December 14, 2015 18:49
This PHP code displays an image before your post title on single posts and archive pages on themes running the old XHTML markup
.post-photo {
margin-bottom: 35px;
display: block;
margin: 0 auto 2.4rem;
}
@braddalton
braddalton / Custom Home Page Template
Created March 12, 2013 04:14
This is a copy of the PHP code included in the Magazine child theme's home.php file and modified for use as a custom page template including widgets the same as the home page displays. I named this file custom.php in the child themes root directory.
<?php
remove_action( 'genesis_loop', 'genesis_do_loop' );
add_action( 'genesis_loop', 'magazine_custom_loop_helper' );
/*
Template Name: Custom
*/
function magazine_custom_loop_helper() {
if ( is_active_sidebar( 'custom-top' ) || is_active_sidebar( 'custom-left' ) || is_active_sidebar( 'custom-right' ) || is_active_sidebar( 'custom-bottom' ) ) {
@braddalton
braddalton / Custom Page Template Widgets
Created March 12, 2013 04:19
This PHP code is a copy of the PHP code used to register widgets in the functions.php file. Copy the code and rename all instances of home to custom and paste at the end of your child themes functions.php file.
/** Register widget areas */
genesis_register_sidebar( array(
'id' => 'custom-top',
'name' => __( 'Custom Top', 'magazine' ),
'description' => __( 'This is the custom top section.', 'magazine' ),
) );
genesis_register_sidebar( array(
'id' => 'custom-left',
'name' => __( 'Custom Left', 'magazine' ),
'description' => __( 'This is the custom left section.', 'magazine' ),
@braddalton
braddalton / Custom Page Template Widget CSS
Last active December 14, 2015 19:59
This CSS code has been copied from the child themes style.css file and modified by changing the home class to custom class for use as a custom page template with widgets like the home page of the Magazine child theme for Genesis.
/* Custom Page Template With Widgets
------------------------------------------------------------ */
.custom-bottom,
.custom-middle,
.custom-top {
clear: both;
font-size: 13px;
line-height: 20px;
margin: 0 0 20px;
@braddalton
braddalton / Remove Footer Widgets Home Page Only
Last active December 14, 2015 21:09
Change the conditional tag to remove footer widgets from other pages!
@braddalton
braddalton / Add Widget To Prose Home Page
Created March 15, 2013 01:00
Paste this code at the end of the Prose child themes init.php file.
genesis_register_sidebar( array(
'id' => 'home-slider',
'name' => __( 'Home Slider', 'prose' ),
'description' => __( 'This is the slider widget area for your homepage.', 'prose' ),
) );
add_action( 'genesis_before_content_sidebar_wrap', 'child_before_content_sidebar_wrap');
function child_before_content_sidebar_wrap'() {
if ( is_home() && is_active_sidebar( 'home-slider' ) ) {
echo '<div id="home-slider">';
@braddalton
braddalton / Display Image Using PHP Action Hook
Last active December 15, 2015 00:39
Upload an image to your WordPress media library and change the image url in this code. Paste the code at the end of your child themes functions.php file. Change the hook depending on your themes specific hooks.
add_action('genesis_before_sidebar_widget_area', 'wpsites_banner_function');
function wpsites_banner_function() {
echo '<div class="widget-logo"><img src="http://yourdomain.com/wp-content/uploads/2013/03/image.png" alt="widget logo" /></div>';
}
@braddalton
braddalton / Display Content Home Page Only
Last active December 15, 2015 00:39
Using your themes hook locations with a conditional tag for the home page, you can display an image or any content in any hook location based on specific conditions like on the home page only.
add_action('genesis_before_sidebar_widget_area', 'wpsites_home_function');
function wpsites_home_function() {
if (is_home() )
echo '<div class="sidebar-home"><img src="http://yourdomain.com/wp-content/uploads/2013/03/yourimage.png" alt="sidebar home logo" /></div>';
}
@braddalton
braddalton / Add Featured Image After Post Title
Last active December 15, 2015 00:39
Display featured image after title but before content on single posts. Change the genesis_hook to your own theme specific hook if needed. You can also change the conditional tag if needed.
add_action( 'genesis_after_post_title', 'wpsites_after_post_title_featured_image' );
function wpsites_after_post_title_featured_image() {
if ( is_single() ) return;
if ( $image = genesis_get_image( 'format=url&size=post-image' ) ) {
printf( '<a href="%s" rel="bookmark"><img class="post-photo" src="%s" alt="%s" /></a>', get_permalink(), $image, the_title_attribute( 'echo=0' ) );
}
}