Posts

web-designFor a clients website I need to remove post info for multiple categories. So, here is the code I use to remove genesis_post_info from multiple categories.

Add above code to the bottom of your child theme’s functions.php file.

custom_contentFor a client’s blog website I need to add a para automatically after each single post, found a snippet from Jeff Starr using a WordPress hook. Here’s how to do.

add_filter('the_content', 'add_post_content')
function add_post_content($content) {
	if(!is_single()) {
		$content .= '<p>YOUR CONTENT GOES HERE'</p>';
	}
	return $content;
}

If you enjoyed and find helpful this article, please consider sharing it.

So, since Genesis 1.6, and probably my favorite part of Genesis 1.6 is the theme support of genesis-structural-wraps. So now you can easily add wraps to the header, nav, subnav, inner, footer-widgets, and footer. If you’ve ever looked at the Visual Markup Guide for the Genesis Framework, you may have noticed that all of the main sections contain a div that wraps around the inner markup except the the ‘inner’ section. Have a look at this:

  • #header > .wrap
  • #nav > .wrap
  • #subnav > .wrap
  • #inner > .wrap, this is what we will be adding
  • #footer-widgets >.wrap
  • #footer > .wrap
Genesis framework

Previously to add an #inner wrap, for example, you had to:
// Add div.wrap inside of div#inner
function child_before_content_sidebar_wrap() {
echo '<div class="wrap">';
}
add_action('genesis_before_content_sidebar_wrap', 'child_before_content_sidebar_wrap');

function child_after_content_sidebar_wrap() {
echo '</div><!-- end .wrap -->';
}
add_action('genesis_after_content_sidebar_wrap', 'child_after_content_sidebar_wrap');

Genesis has made it easy for us to add the additional wrapper by using hooks. All you need to do is open up the functions.php file in your child theme and add the following code. The code should be placed at the end of the file, just before the closing ?> if there is one.
add_theme_support( 'genesis-structural-wraps', array( 'header', 'nav', 'subnav', 'inner', 'footer-widgets', 'footer' ) );

The style changes

By default the sample child theme for  genesis  is boxed in a 960px #wrap that constrains all the elements inside to that width centering them on the page. Find #wrap in your sample child theme style.css around line 162.
Change:
#wrap {
background-color: #fff;
margin: 0 auto 10px;
width: 960px;
}

to:
#wrap {
background-color: #fff;
}

This will remove the contraint and allow our elements inside to span as far as we please.

Add styles for the wrap divs that is inside each our main div structures. This style will set each area to 960px width with the margin:0 auto; centering them on the page.
.wrap {
&nbsp;&nbsp;&nbsp;&nbsp;margin: 0 auto;
&nbsp;&nbsp;&nbsp;&nbsp;width: 960px;
}

NOTE: Can be more specific to each area by adding the id of each section before .wrap for example:
#nav .wrap { width: 900px; }
Will set the nav to be shorter than the other areas.

Find each main structural div and remove its width. The width we set for .wrap will handle this. Search for #header, #nav, #subnav, #inner, #footer-widgets & #footer and remove the width set for each.

Hope this will help you to make your theme more better. 🙂

There’s a lot of small code snippets I use often. This is where I’ll collect them. If you have any quick tips, feel free to share in the comments.

Genesis-Theme-Framework-Visual-Hook-Reference

Force a page layout
This is very useful for ensuring custom pages you build for a client aren’t broken by them changing the page layout (ex: home page). Or, changing the page layout to something other than the default on archive pages (ex: category). The example below is to set the category page to Sidebar-Content-Sidebar.

// Force layout on category
add_filter('genesis_pre_get_option_site_layout', 'child_category_layout');
function child_category_layout($opt) {
if ( is_category() )
$opt = 'sidebar-content-sidebar';
return $opt;
}

Set default page layout
// Register default site layout option
genesis_set_default_layout( 'full-width-content' );

Setup the child theme
This is what I include at the top of my functions.php file in my child themes. Any time below you see an add_action or add_filter, that part goes in the setup function, and the function itself goes after the setup function.
// Start the engine
require_once(TEMPLATEPATH.'/lib/init.php');
// Setup the child theme
add_action('after_setup_theme','child_child_theme_setup');
function child_child_theme_setup() {
// ** Backend **
// Remove Purchase Themes menu link from dashboard
remove_theme_support('genesis-purchase-menu');
// ** Frontend **
}

Unregister unused page layouts
// Unregister other site layouts
genesis_unregister_layout( 'content-sidebar' );
genesis_unregister_layout( 'sidebar-content' );
genesis_unregister_layout( 'content-sidebar-sidebar' );
genesis_unregister_layout( 'sidebar-sidebar-content' );
genesis_unregister_layout( 'sidebar-content-sidebar' );

Add Image Sizes
This adds an image size named ‘feature’ with a fixed size of 600×250.  See Mark Jaquith’s post for details.
add_image_size('feature', 600, 250, true);

Modify Post Info

Shortcode Reference
add_filter('genesis_post_info', 'child_post_info_filter');
function child_post_info_filter($post_info) {
$post_info = '[ post_date ] by [ post_author_posts_link ] at [ post_time ] [ post_comments ] [ post_edit ]';
return $post_info;
}

Remove Post Info
remove_action('genesis_before_post_content', 'genesis_post_info');

Modify Post Meta
add_filter('genesis_post_meta', 'child_post_meta_filter');
function child_post_meta_filter($post_meta) {
$post_meta = '[ post_categories ] Tagged with [ post_tags ]';
return $post_meta;
}</code>
<strong>Remove Post Meta</strong>
<code>remove_action('genesis_after_post_content', 'genesis_post_meta');

Change Excerpt More text […]

function child_excerpt_more($more) {
&nbsp;   return '[.....]';
}
add_filter('excerpt_more', 'child_excerpt_more');

Remove Footer
remove_action('genesis_footer','genesis_do_footer');

Remove Footer and Footer Markup
// Remove Footer
remove_action('genesis_footer', 'genesis_do_footer');
remove_action('genesis_footer', 'genesis_footer_markup_open', 5);
remove_action('genesis_footer', 'genesis_footer_markup_close', 15);

Customize the Search Form text
add_filter('genesis_search_button_text', 'child_custom_search_button_text');
function child_custom_search_button_text($text) {
return esc_attr('');
}

Remove Breadcrumbs
add_filter('genesis_breadcrumb_args', 'child_custom_breadcrumb_args');
function child_custom_breadcrumb_args($args) {
$args['sep'] = ' > ';
$args['labels']['prefix'] = '';
return $args;
}

Customize the Site Title (in #header)

This is useful if you want to use the default site title (Settings > Title) but style different elements of it differently. This specific code searches for “of” in the site title, and changes it to <em>of</em>.
// Customize the site title
add_filter('genesis_seo_title','child_customize_site_title', 10, 3);
function child_customize_site_title($title, $inside, $wrap) {
$custom = str_replace("of", "<em>of</em>", $title);
return $custom;
}

Customize the Site Description (in #header)
add_filter('genesis_seo_description','child_customize_site_description', 10, 3);
function child_customize_site_description($description, $inside, $wrap) {
$custom = str_replace("Redefining", "<strong>Redefining</strong>", $description);
return $custom;
}

Remove the Post Title
// Remove Post Title
remove_action('genesis_post_title','genesis_do_post_title');

Remove Page Titles
/** Remove page titles */
add_action( 'get_header', 'child_remove_page_titles' );
function child_remove_page_titles() {
if ( is_page() && ! is_page_template( 'page_blog.php' ) )
remove_action( 'genesis_post_title', 'genesis_do_post_title' );
}

Display Description of Menu Items

To add a description to a menu item, go to Appearances > Menus. At the top right click “Screen Options”, then check “Description”. Now you can click the dropdown arrow next to menu items and add a description. The below code will make it visible on the site.
// Display Description of Menu Items
add_filter( 'walker_nav_menu_start_el', 'child_add_description', 10, 2 );
function child_add_description( $item_output, $item ) {
$description = __( $item->post_content );
return preg_replace(&nbsp; '/(<a.*?>[^<]*?)</', '$1' . '<span >' . $description . '</span></',  $item_output);
}

Register a Sidebar
genesis_register_sidebar(array(
&nbsp;   'name'=>'Homepage Widgets',
'id' => 'homepage-widgets',
'description' => 'This shows up at the bottom of the homepage.',
));

Unregister a Sidebar
unregister_sidebar('sidebar-alt');

Customize Read More Link
// Customize Read More Link
add_filter( 'excerpt_more', 'child_more_link' );
add_filter( 'get_the_content_more_link', 'child_more_link' );
add_filter( 'the_content_more_link', 'child_more_link' );
function child_more_link($more_link, $more_link_text) {
&nbsp;   return sprintf('%s', get_permalink(), 'Read More');
}