Adding a Featured Image to Leaderboard of Web Design Serivces Website

featured leaderboard image

A leaderboard can be a nice visual addition to website pages. So, how can we add this to a WordPress site, and make it easy for a customer to as well? The answer is to pull in the Featured Image into our page using a little PHP recipe and a dash of CSS styling:

A modern, user-friendly website can boost your online engagement and help build your business. Contact our professional web design team today for a beautiful, custom WordPress website.

Contact Us page leaderboard image
Example of a Contact Us page leaderboard image.
  1. Check functions.php in the theme directory to make sure support for Post Thumbnails on posts and pages is enabled. Look for:
    add_theme_support( 'post-thumbnails' );

    If that code isn’t part of functions.php, add the code to functions.php to enable post thumbnails support.

  2. For each page you want to add a leaderboard image to, look for the Featured Image box on the right side of the editor and assign a featured image.
  3. Add the code below to your WordPress page template where you want the leaderboard image to appear. Note the else statement that provides a different class if a featured image isn’t assigned; more on that in the next step:
            echo '<div class="leaderboard-image">';
            echo '</div>';
            echo '<div class="leaderboard-without-image"></div>';
  4. In your theme’s style sheet, add your desired styling for the leaderboard image. Below is an example that includes a fall back for Pages where a featured image isn’t assigned. Adjust the styles as needed for the site you are working on:
    /* Featured image as leaderboard*/
    .leaderboard-without-image {
    border: 5px solid #ffffff;
        box-shadow: 0 0 15px rgba(0, 0, 0, 0.4);
        margin-bottom: 60px;
        margin-top: 15px;
    .leaderboard-without-image {
    background: url(images/default-leaderboard.jpg) center top no-repeat;

Inspired by a request from a customer, I found some code and merged it with our standard leaderboard code to make it possible to add a link to a featured image in the leaderboard using built-in WordPress custom fields. That’s right, Advanced Custom Fields is not needed for this.

Note: The code below assumes you are adding an external link. If you are adding an internal link, modify the code and remove the “target=”_blank” portion so the link will open in the same tab/window.

Here’s the updated code to add to your WordPress page template:

<?php $name = get_post_meta($post->ID, 'ExternalUrl', true);
if( $name ) { ?>
<div class="leaderboard-image">
<a href="<?php echo $name; ?>" target="_blank"><?php the_post_thumbnail(); ?></a>
<?php } else {
echo '<div class="leaderboard-image">';
echo '</div>';
} ?>

Once that has been added:

  1. Create or edit the page where you are adding the leaderboard and link.
  2. Make sure custom fields are visible by clicking on Screen Options in the upper right corner and that the box next to Custom Fields is checked.
  3. Click on Screen Options again to close the panel and scroll down past the page editor until you see the Custom Fields box.
  4. Under the Name field, click the Enter New link and type ExternalURL into the Name field.
  5. Place the link you want the featured image leaderboard to link to in the value field.
  6. Save or Update the page.

Please note: When you copy the code from these areas, that they will properly indent and each line will have the correct format when you paste it into your code editor program.

For more tutorials and information on how to customize your website or get started with the design process, please check our Web Design Services channel!

InMotion Hosting Contributor
InMotion Hosting Contributor Content Writer

InMotion Hosting contributors are highly knowledgeable individuals who create relevant content on new trends and troubleshooting techniques to help you achieve your online goals!

More Articles by InMotion Hosting

Was this article helpful? Join the conversation!