follow mejoin mesubscribe
Get Your own Toll Free Number

Genesis Custom Widget Post Titles

First, let me say that the Genesis Featured Posts widget is a wonderfully easy way to easily add customized content to a widgeted area. And, Nick’s Genesis Featured Widget Amplified extends functionality greatly, including the option to automatically shorten post titles to a specific number of characters. However, sometimes shortening post titles automatically can result in words less meaningful than you would like. The following functions allow you to limit the post title length on a widget to widget basis, but replace the title with a custom field. To use these, you simply need to create a post with a custom field calledlimit Genesis Custom Widget Post Titles child_home_title and then put anything other than 0 in the title character limit field of the widget.

/**
 * Custom Widget Titles for Home
 *
 * @author Jen Baumann
 * @link http://dreamwhisperdesigns.com/?p=1005
 */
remove_action( 'gfwa_before_post_content', 'gfwa_do_post_title', 10, 1 );
add_action( 'gfwa_before_post_content', 'custom_gfwa_do_post_title', 10, 1 );
function custom_gfwa_do_post_title( $instance ) {
	$link = $instance['link_title_field'] && genesis_get_custom_field( $instance['link_title_field']) ? genesis_get_custom_field( $instance['link_title_field']) : get_permalink();

    $wrap_open = $instance['link_title'] == 1 ? sprintf( '<a href="%s" title="%s">', $link, the_title_attribute( 'echo=0' ) ) : '';
    $wrap_close = $instance['link_title'] == 1 ? '</a>' : '';

    if ( !empty( $instance['show_title'] ) && !empty( $instance['title_limit'] ) )
        printf( '<h2>%s%s%s%s</h2>', $wrap_open, genesis_get_custom_field( 'child_home_title' ), $instance['title_cutoff'], $wrap_close );
    elseif ( !empty( $instance['show_title'] ) )
        printf( '<h2>%s%s%s</h2>', $wrap_open, the_title_attribute( 'echo=0' ), $wrap_close );
		
}

You should add this anywhere after this line: require_once(TEMPLATEPATH.'/lib/init.php'); but before the final ?> tag at the end of the file.

About Jennifer Baumann

I am an avid horseback rider, animal lover, and freelance designer. I love working with WordPress and Genesis and work for Copyblogger Media as a Technical Support Advocate.

Dream Whisper Designs is Powered by Genesis

StudioPress Premium WordPress Themes

Genesis empowers you to quickly and easily build incredible websites with WordPress. Whether you're a novice or advanced developer, Genesis provides the secure and search-engine-optimized foundation that takes WordPress to places you never thought it could go. It's that simple - start using Genesis now!

Take advantage of the 6 default layout options, comprehensive SEO settings, rock-solid security, flexible theme options, cool custom widgets, custom design hooks, and a huge selection of child themes ("skins") that make your site look the way you want it to. With automatic theme updates and world-class support included, Genesis is the smart choice for your WordPress website or blog.