One of the many useful modules of JetPack is Related Posts. In this tutorial I share a few code snippets that I used in one of my recent site build with featured images set to appear via the plugin's "Use a large and visually striking layout" setting. More here.
Change the size of images
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// change thumbnail size | |
function jetpackchange_image_size ( $thumbnail_size ) { | |
$thumbnail_size['width'] = 350; | |
$thumbnail_size['height'] = 200; | |
// $thumbnail_size['crop'] = true; | |
return $thumbnail_size; | |
} | |
add_filter( 'jetpack_relatedposts_filter_thumbnail_size', 'jetpackchange_image_size' ); |
Change the width and height from their default values of 300px and 200px to your desired values in the above.
Remove in and quotes around category names
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
add_filter( 'jetpack_relatedposts_post_category_context', 'sk_customize_jp_context', 10, 2 ); | |
function sk_customize_jp_context( $post_cat_context, $category ) { | |
$post_cat_context = sprintf( | |
// _x( 'In "%s"', 'in {category/tag name}', 'jetpack' ), /* Default */ | |
_x( '%s', 'in {category/tag name}', 'jetpack' ), | |
$category->name | |
); | |
return $post_cat_context; | |
} |
Thanks to Chetan Chauhan.
Reposition Related Posts
To remove Related Posts from their default location on single Posts:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Remove JP Related Posts from its default location | |
function jetpackme_remove_rp() { | |
$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 ); |
To add them at your desired location in Genesis:
To view the full content, please sign up for the membership.
Already a member? Log in below or here.