WP Smith

Creating WordPress & Genesis Websites Since 2010

  • Home
  • About
  • Services
  • Blog
  • Contact

Aug 12 2012

Genesis Post Class Patch

Recently, I was asked about a fix for the Genesis Post Class not saving. Here is a patch that will stop executing when Genesis upgrades to 1.9.0 which will re-write this section of the code.

This code does assume WordPress 3.4.x which uses wp_get_theme() instead of get_theme_data(). Please use accordingly in functions.php.

Written by Travis Smith · Categorized: Genesis

Jul 18 2012

How to Filter the Genesis Sidebar Defaults

By default, Genesis registers its sidebars. For styling reasons, we may want to filter those; however, this can prove difficult with Genesis if you don't understand how Genesis calls the various files and their order. WordPress follows this priority order:

  1. Plugins
  2. Child Theme
  3. Parent Them

First, WordPress gives prioirity to plugins, so modifying these defaults works well in a core functionality plugin.

Second, Genesis "teaches" many people to place their content below the statement require_once( get_template_directory() . '/lib/init.php' ) that often appears at the top of the functions.php file. In essence, by doing this you are executing genesis_init and genesis_setup hooks. So anything that hooks to those functions that appear below (and even before) this statement WILL NOT be executed.

So, let me demonstrate:

THIS WILL NOT WORK!

So, the way I build my child themes is to use functions for everything, so there is no dropping in code in functions.php, like so many do (and even as WordPress and Genesis encourages). While Genesis can do things like add_theme_support(), or genesis_register_sidebar(), etc. These are best placed inside a function that hooks to genesis_setup, genesis_init, or after_setup_theme. However, this is more about the philosophy and the praxis of child theme development.

So, if you use your functions.php as most people do, my recommendation is to either (1) add this to your core functionality plugin, or (2) develop another plugin (drop-in [plugin file that is placed in wp-content/plugins directly, see also hakre on wordpress's (sic) post on Must-Use Plugins and Drop-Ins] even). To help you, here is the plugin code you will need:

Or you can download it here: [download id="20"]

Once you download the file, just upload and install just like you would any other plugin.

Written by Travis Smith · Categorized: Genesis

Jul 17 2012

How to Remove the Website Field from Genesis Comments Form

In Genesis, the comments form is extremely easy to modify. In this mini-tutorial, I will show you how to modify the comments form to remove the URL or website field. genesis_comment_form_args has three field arguments by default: name/author, email, and url. In this example, I am only removing the URL field argument.

Written by Travis Smith · Categorized: Genesis

Apr 30 2012

How to Prevent Featured Images in Custom Post Types

So recently, someone asked if they could enabled Genesis Featured Images in Genesis > Theme Settings yet "disable" them for custom post types. While there is no option for this, it can be done! This is a rather simple task that can be complicated if post types are mixed and other circumstances. However, let's assume a simple setup.

In functions.php or your core functionality plugin where you created the custom post types, enter this code:
[php]
add_action( 'genesis_before_post_content', 'wps_do_post_image_check' );
/*
* Remove genesis_do_post_image() action if on post type archive of
* a custom post type
*
* @global stdClass $post Post object
* @uses genesis_get_option() Gets the genesis option for content archive thumbnails
*/
function wps_do_post_image_check() {
global $post;
if ( ! is_singular() && genesis_get_option( 'content_archive_thumbnail' ) && is_post_type_archive() && ! in_array( $post->post_type, array( 'page', 'post', 'attachment' ) ) )
remove_action( 'genesis_post_content', 'genesis_do_post_image' );
}
[/php]

NOTE: Though posts, pages, and attachments by default do not have archive pages, I cannot assume that in this code snippet.

Written by Travis Smith · Categorized: Genesis

Apr 05 2012

How to Create a Widgetized Area on a Page Templates in Genesis?

Previously, you would check to see if the dynamic sidebar was active and then you would display the dynamic sidebar. Or, maybe you call the dynamic sidebar and include some default information if the sidebar was not active.

Genesis has now streamlined this for you. While version 1 is not 100% perfect, in Genesis 1.9 expect a minor improvement with the new genesis_widget_area() function. In this brief tutorial, I will walk through a home template and a portfolio widgetized template.

Home

So instead of something like this on a home page (home.php):
[php]
if ( is_active_sidebar( 'home' ) || is_active_sidebar( 'home-left' ) || is_active_sidebar( 'home-right' ) ) {

dynamic_sidebar( 'home' );

if ( is_active_sidebar( 'home-left' ) ) {
echo '</pre>
<div id="homepage-left">';
dynamic_sidebar( 'home-left' );
echo '</div>
<pre>
<!-- end #homepage-left -->';
}

if ( is_active_sidebar( 'home-right' ) ) {
echo '</pre>
<div id="homepage-right">';
dynamic_sidebar( 'home-right' );
echo '</div>
<pre>
<!-- end #homepage-right -->';
}

}
else {
genesis_standard_loop();
}
[/php]

You can now have something as simple as this:
[php]

if ( ! genesis_widget_area( 'home', array( 'before' => '<div class="home-slider widget-area">' ) ) && ! genesis_widget_area( 'home-left' ) && ! genesis_widget_area( 'home-right' ) )
genesis_standard_loop();
[/php]

Or, if you prefer (without the loop default):
[php]
genesis_widget_area( 'home', array( 'before' => '<div class="home widget-area">', ) );
genesis_widget_area( 'home-left', array( 'before' => '<div class="home-left widget-area">', ) );
genesis_widget_area( 'home-right', array( 'before' => '<div class="home-right widget-area">', ) );
[/php]

Regardless, you still need to register the widget/sidebar areas in functions.php.
[php]
// Register Sidebars
genesis_register_sidebar(
array(
'id' => 'home',
'name' => __( 'Home', 'child' ),
'description' => __( 'This is the home main section.', 'child' ),
)
);

genesis_register_sidebar(
array(
'id' => 'home-left',
'name' => __( 'Home Left', 'child' ),
'description' => __( 'This is the home left section.', 'child' ),
)
);

genesis_register_sidebar(
array(
'id' => 'home-right',
'name' => __( 'Home Right', 'child' ),
'description' => __( 'This is the home right section.', 'child' ),
)
);
[/php]

Widgetized Page Template: Portfolio

You could also create a portfolio page template this way as well. First, create a file named page-portfolio.php (NOTE: A file named this way will automatically become the page template of any page named Portfolio, so if you want to avoid this [though against WordPress Coding Standards], name the file page_portfolio.php). Then copy the following into it. This will go into your child theme folder along with home.php (if there is one), functions.php, and style.css.
[php]
/**
* Template Name: Portfolio Template
*
* This file is responsible for generating a widgetized
* portfolio page template forcing a full-width
* layout, removes post info & post meta and adds portfolio class.
*
* @category Child
* @package Templates
* @author Travis Smith <[email protected]>
* @copyright Copyright (c) 2012, Travis Smith
* @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
* @since 1.0.0
*
*/

//Remove Post Info / Meta
remove_action( 'genesis_before_post_content', 'genesis_post_info' );
remove_action( 'genesis_after_post_content', 'genesis_post_meta' );

//Forces pre-layout
add_filter( 'genesis_pre_get_option_site_layout', '__genesis_return_full_width_content' );

add_filter( 'body_class', 'minfolio_add_portfolio_widgetized_body_class' );
/**
* Add page specific body class
*
* @param $classes array Body Classes
* @return $classes array Modified Body Classes
*/
function minfolio_add_portfolio_widgetized_body_class( $classes ) {
$classes[] = 'portfolio-widgetized';
return $classes;
}

// Remove default content / loop
remove_action( 'genesis_loop', 'genesis_do_loop' );
add_action( 'genesis_loop', 'minfolio_portfolio_widget' );
/**
* Add the Portfolio widget area
*
* @uses genesis_widget_area() Conditionally displays a sidebar, wrapped in a div by default.
*/
function minfolio_portfolio_widget() {
genesis_widget_area( 'portfolio', array( 'before' => '<div class="portfolio widget-area">', ) );
}
[/php]

If you don't want the portfolio widget area to be wrapped in a div you would use this instead:
[php]
genesis_widget_area( 'portfolio', array( 'before' => '', 'after' => '', ) );
[/php]

Hopefully the commentation makes the code easy to follow. If you are wondering what all the @category, @package, @uses, etc. are, don't worry, you are not the only ones. Funny thing is that Genesis didn't start getting some of this type of documentation until Genesis 1.7 and 1.8 (primarily). For more information, please refer to Michael Fields's Theme Documentation post. If you are a child theme developer, I highly encourage you to have your code vetted and validated with @GaryJ (Gary Jones). You can contact Gary via Twitter, the #genesiswp IRC channel (almost any time! though if he doesn't answer leave the IRC open [if you can unlike me] until he does...he ALWAYS does), Facebook, or somewhere. You are guaranteed to learn something!

NOTE: Currently, the default 'before' argument is '<div class="widget-area">'. Hopefully in the next version of Genesis, this will change to something like this: '<div class="' . $id . ' widget-area">' to include the id automatically in the argument as that would be extremely helpful thus reducing the code for me to just genesis_widget_area( 'home' );

Written by Travis Smith · Categorized: Genesis

  • « Previous Page
  • 1
  • 2
  • 3
  • 4
  • 5
  • …
  • 20
  • Next Page »
  • Twitter
  • Facebook
  • LinkedIn
  • Google+
  • RSS

Copyright © 2025 � WP Smith on Genesis on Genesis Framework � WordPress � Log in