Breaking News
Home / wordpress tutorials / featured image hack in wordpress

featured image hack in wordpress

One feature of wordpress  is the ability to assign a featured image  to each post. As a beginner, I know you are not familiar with the word ‘featured Image’.

What is a featured image?

A featured Image mostly known as post thumbnail by wordpress theme developers is a WordPress feature which allows a blogger or a website Administrator to    assign an image to each posts, pages and custom post type.

How to add a featured image to a blog post in wordpress

To add a featured image in wordpress, follow the steps below

  • Download the image you want to use to your computer
  • Login your wordpress admin dashboard
  • Click on new post to write your content, this will open the text editor.
  • check the button of the page  at the right and you will see the featured image  button

set featured image in worddpress

  • click on it  and you will be taken to the media library of your blog.
  • Click on upload to select the image  you want to use as the featured image from your computer

how to set featured image in wordpress.

  •  After uploading the image,enter the description for Seo purpose

How to require a featured image in a post

As a beginner, sometimes we just hit the published button forgetting to set a featured image. with this code below ,without setting a featured image for a post, the post will be saved but not published not until you set a featured image for the post.

To require a featured image in a post before publishing, paste the code below in the function file of your theme .

add_action(‘save_post’, ‘wpds_check_thumbnail’);
add_action(‘admin_notices’, ‘wpds_thumbnail_error’);
function wpds_check_thumbnail($post_id) {
// change to any custom post type
if(get_post_type($post_id) != ‘post’)
if ( !has_post_thumbnail( $post_id ) ) {
// set a transient to show the users an admin message
set_transient( “has_post_thumbnail”, “no” );
// unhook this function so it doesn’t loop infinitely
remove_action(‘save_post’, ‘wpds_check_thumbnail’);
// update the post set it to draft
wp_update_post(array(‘ID’ => $post_id, ‘post_status’ => ‘draft’));
add_action(‘save_post’, ‘wpds_check_thumbnail’);
} else {
delete_transient( “has_post_thumbnail” );
function wpds_thumbnail_error()
// check if the transient is set, and display the error message
if ( get_transient( “has_post_thumbnail” ) == “no” ) {
echo “<div id=’message’ class=’error’><p><strong>You must select Featured Image. Your Post is saved but it can not be published.</strong></p></div>”;
delete_transient( “has_post_thumbnail” );

with the code pasted in the function file of your active theme, if a featured image is not set for a post, the post will not be published but saved.

Check Also

how to start a blog

how to start a blog in 2018

An introduction to Blogging Blogging is one of the oldest forms of Social Media, it is …

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.