This is a page for WordPress Code Snippets, but specifically for the Genesis Framework. As I come across helpful Genesis WordPress code snippets or create new code, I will share here in hopes to benefit other WordPress users out there:
Table of Contents
Add a Custom Favicon
Add a Read More Link to post excerpt
Display Featured Image & Custom Size
Insert Content Before Jetpack Social Sharing and Related Posts
Change Default Search Text
Display Featured Image & Custom Size
// Register a custom image size for Singular Featured images //Choose custom image size and remember to Regenerate Thumbnails add_image_size( 'singular-featured-thumb', 768, 450, true ); //Hook to add image before entry content add_action( 'genesis_before_entry_content', 'tm_display_featured_image' ); //Function to display image function tm_display_featured_image() { if ( ! is_singular( array( 'post', 'page' ) ) ) { return; //ends function if not singular post or page } if ( ! has_post_thumbnail() ) { return; //ends function if no thumbnail chosen } // Display featured image above content echo '<div class="singular-featured-image">'; genesis_image( array( 'size' => 'singular-featured-thumb' ) ); echo '</div>'; }
Add a Read More link to Post Excerpt
// Add Read More Link to Excerpts add_filter('excerpt_more', 'get_read_more_link'); add_filter( 'the_content_more_link', 'get_read_more_link' ); function get_read_more_link() { return '... <a href="' . get_permalink() . '">[Read More]</a>'; }
Add a Custom Favicon
/** Adding custom Favicon */ add_filter( 'genesis_pre_load_favicon', 'custom_favicon' ); function custom_favicon( $favicon_url ) { return 'http://example.com/wp-content/uploads/favicon.png'; }
Insert Content Before Jetpack Social Sharing and Related Posts
<h3>Insert Content Before Jetpack Social Sharing and Related Posts</h3> <pre class="wrap:true lang:default decode:true">//Remove original Jetpack Social Sharing location add_action( 'init', 'custom_init', 11 ); function custom_init() { //* if sharing_display() function does not exist, return if( ! function_exists( 'sharing_display' ) ) { return; } //* remove the callback sharing_display() for the 'the_content' filter. remove_filter( 'the_content', 'sharing_display', 19 ); } // Remove JetPack Related Posts function jetpackme_remove_rp() { if ( class_exists( 'Jetpack_RelatedPosts' ) ) { $jprp = Jetpack_RelatedPosts::init(); $callback = array( $jprp, 'filter_add_target_to_dom' ); remove_filter( 'the_content', $callback, 40 ); } } add_filter( 'wp', 'jetpackme_remove_rp', 20 ); //Putting Jetpack Social Sharing after the content add_action( 'genesis_after_entry_content', 'reposition_jetpack', 5 ); function reposition_jetpack() { if ( is_singular( 'post' ) && function_exists( 'sharing_display' ) ) { sharing_display( '', true ); } } //Putting JetPack Related Posts after the content function wpb_jp_posts() { echo do_shortcode(' [jetpack-related-posts] '); } add_action( 'genesis_after_entry_content', 'wpb_jp_posts', 10 ); /* Now insert New Hook Before Social Sharing by using the 'genesis_after_entry_content' but a priority number lower than 5 (as social sharing was 5 and related posts was 10). */</pre>
Change Default Search Text
//Change default search text function themeprefix_search_button_text( $text ) { return ( 'Custom search phrase...'); } add_filter( 'genesis_search_text', 'themeprefix_search_button_text' );