What's WP
Our everything is about WordPress - best choice of WordPress users!
How to Showcase Featured Post in WordPress Homepage

How to Showcase Featured Post in WordPress Homepage

Due to the fierce competition among countless websites on the Internet, many webmasters have focused on the development of homepage, hoping the design can be attractive enough to arouse people’s interests in the first sight. To achieve this goal, more and more website owners choose to showcase the featured post in their WordPress homepage for it not only can inform visitors of the latest updates, but also can enrich the content of the homepage aesthetically.

As many of our readers have no idea how to do this, we’d like to showcase the detailed steps of how to display the featured post in WordPress.

wordpress featured posts

Add the Function of Featured Post

In fact, you can add this function in both your theme and your plugin. As the website theme is less likely to be changed than a plugin, we simply assume you want to add it in your theme.

At first, you need to log into your WordPress admin to go for the functions.php file. This file is used to define the functions of WordPress themes. You can delete, add, and change some functions as you wish by adding some lines of code.

This file can be found in your theme’s folder. You can also access it from WordPress Dashboard < Appearance < Editor. After making sure you have selected the right theme, then you only need to click functions.php in the list on the right column. functions file

We have already come up the code needed to add the featured post function into your theme. The only thing you need to do is to copy and paste the following lines of code into anywhere within the functions.php file.

add_theme_support( 'featured-content', array(  
    'featured_content_filter' => 'mytheme_get_featured_content',  

After saving the changes, now you need to go to Settings < page to make further configuration. You can set the tag name, decide the number of featured posts, and choose whether to hide the tag from displaying in post meta and tag clouds.

Display Featured Post

After adding the function successfully in your WordPress theme, now you can display the featured content in the homepage.

Now, you need to open the functions.php file again to put the featured posts in array with the help of the following code.

function yourthemename_get_featured_content() {  
    apply_filters( ' yourthemename _featured_content', array() );  

It is worth mentioning that the name of your theme needs to be correct with a low case.

The next thing you need to do is to customize the featured post by deciding the size of thumbnails. After all, how the featured image looks like can affect the overall layout of your homepage to some extent.

To do this, simply paste the following lines of code into the functions.php file, and change the size numbers as you wish.

add_theme_support( 'post-thumbnails' );
add_image_size( 'yourthemename-featured-thumbnail', 200, 200, true ); 

Next, in order to make your featured content in a proper HTML structure, you need to set up a new template and name it as featured.php. The code that needs to be added into this file is displayed in the following.

<div class="featured-post clearfix">  
    <figure class="post-thumbnail">  
        <?php if ( has_post_thumbnail() ): ?>
        <?php endif; ?>
    <div class="post-entry">  
        <h3 class="post-title"><a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a></h3>  
        <?php the_excerpt(); ?>  

The final step is to call that newly-created template in action. Simply find the index.php file in the Editor tab of the Experience category, and add the following code into it.

<?php if ( yourthemename_get_featured_content(1) ){ ?>  
    <div id="featured">  
        <h2><?php _e( 'Featured Content', 'yourthemename' ); ?></h2>
        <?php for ($i=0; $i <count($featured) ; $i++) { 
            setup_postdata( $post );
            get_template_part( 'featured', get_post_format() );
<?php } ?>


Susan Rose is a freelance writer who has a deep knowledge about WordPress. She loves everything related to website building since the freshman year at Christopher Newport University, and loves to share her experience with people all over all the world. This girl is popular among our readers as she is outgoing and energetic. In the daily life, Susan loves detective novels as it can train her logical thinking and creativity.


Want to Learn More About WordPress?

Get Our Free Themes, Plugins, Support, SEO Tips, and Other Tutorials!

Email *