This tutorial provides the code which enables you to add a custom image for each post displayed using the Genesis featured posts widget. By default, the featured posts widget uses the featured image.
If a custom image is added to any single post, the custom image is displayed in the featured posts widget and not the featured image. If no custom image is added, the featured image is used.
Here’s a screenshot showing the same single post ( 1 ) displayed on a archive ( left ) which uses the default featured image and ( 2 ) in the primary sidebar ( right ) which uses the custom image.
Here’s the demo showing how it works.
Demo Video #
The demo video shows you how to follow the 3 steps to install the code, setup and add the custom featured image for use in the Genesis featured posts widget.
Code Functionality
The code enables you to:
- Use a different/custom featured image in the Genesis featured posts widget.
- Choose the size and alignment of the custom image using the Genesis featured posts widget settings.
- Display the default featured image when no custom image added.
Installation Steps #
Installation of the code only requires 3 steps after downloading the zip file below.
Step 1 : Upload the file named custom-featured-post-widget.php to your child themes root directory.
Step 2 : Add the following PHP code to the end of your child themes functions.php file.
include_once( get_stylesheet_directory() . '/featured-posts.php' );
add_action( 'widgets_init', 'custom_featured_posts_image' );
function custom_featured_posts_image() {
register_widget( 'Featured_Posts' );
}
Step 3 : Install the ACF plugin and create a new field named image like your see in the following ACF settings:
Here’s the code for logged in members:
Was This Tutorial Helpful?