How To Require a Featured Image Before You Can Publish a Post

Are you looking for a way to require a featured image before you can publish a post? This snippet will require that you have added a featured image before your post can be published. If you try to publish a post without a featured image after adding this snippet, you will receive this message: “You must select Featured Image. Your Post is saved but it can not be published.”


All you have to do is add this code to your theme’s functions.php file or in a site-specific plugin:

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" );

Setting a Fallback for Post Thumbnails in WordPress

One of the countless things that I love about WordPress is how easy and efficient the process of adding new content is. All you have to do is provide the art and copy and your theme will take care of the rest. While this workflow is usually smooth, there are times the end user can miss a step or two. I’ve noticed when working on larger sites with multiple authors one of the most common things to slip through the cracks is setting a featured image. While this shouldn’t break your theme, it can create layout inconsistencies or (shudder) broken images. Lucky for us, we can easily provide a fallback, and I’ll tell you how.

WordPress Post Thumbnails

Post Thumbnails were introduced in WordPress 2.9 [Source: WordPress Codex] and have since become somewhat of a standard for theme developers. If a theme declares support for this functionality, it allows authors to set an image that will represent Posts, Pages, or Custom Post Types. How this image is utilized is completely dependent on the theme. A lot of themes will use a featured image to accompany excerpts, but that’s just one example.

Setting A Fallback

If your theme uses Post Thumbnails, it is probably wise to set a backup. That way if you (or one of your authors) forgets to set a featured image before publishing a post it will not break the layout. One way to do this is by grabbing the first image from the post, and returning it if no post thumbnail exists. First, add the following to your functions.php:

//Call the first uploaded image in the post
function fallback_image() {
$files = get_children('post_parent='.get_the_ID().'&post_type=attachment
if($files) :
$keys = array_reverse(array_keys($files));
$num = $keys[$j];
$image=wp_get_attachment_image($num, 'thumbnail', true); //Set your image size and crop to true or false here
$imagepieces = explode('"', $image);
$imagepath = $imagepieces[1];
print "<img class='featured' alt='$the_title' src='$fallback' />";

Now, determine where in your theme the featured image is used (Hint: Check index.php, loop.php, home.php, etc.). Look for the call to get_the_post_thumbnail and replace it with the following:

<?php if ( (function_exists('has_post_thumbnail')) && (has_post_thumbnail()) ) { //If a featured image was set, return it
echo get_the_post_thumbnail($post->ID);
} else { //If it wasn't set, return the fallback
echo fallback_image();
} ?>

Note: I am assuming that your theme has already established support for Post Thumbnails. If it hasn’t you’ll need to add that functionality. Don’t worry, it’s easy. Just look to the Codex to learn how to enable support for Post Thumbnails.


This is just one way you can handle fallbacks for featured images. I have seen a lot of themes let allow you set a single default image, a company logo for example, as a fallback and that seems to work perfectly fine as well. The decision is ultimately up to you.

15 Tips for Using Google Search Console to Effectively Grow Your Website Traffic

Google Search Console is a powerful free tool created by Google to help website owners understand how Google sees their website. Unfortunately, most businesses don’t know how to effectively use the full power of Google Search Console to increase their website traffic. In this article, we will show you how to properly use Google Search Console to improve your website SEO and get more visitors.

What is Google Search Console?

Google Search Console is a free tool offered by Google to help website owners monitor and maintain their site’s presence in Google search results.

It provides essential marketing data that you need to start tracking from day one. It also alerts you about errors, security issues, and indexing problems that may affect your website’s search rankings.

You can use all this information in your WordPress SEO strategy to increase your website traffic.

The sad part is that most businesses don’t utilize the full power of Google Search Console because majority of them think that just adding their website to Google Search Console is enough.

There’s so much more that you can be doing.

If you’re not leveraging all of the powerful features that Google Search Console offers, then you’re missing out.

Luckily, we’re here to help. We have created this ultimate Google Search Console guide to help you grow your website like a Pro.

Note: Since this is a comprehensive guide, we have added a table of contents for easier navigation.
Posted in SEO

Open Graph Meta Tags: Everything You Need to Know

Are you wondering how to make your content more clickable, shareable, and noticeable on social media?
Open Graph meta tags are the solution.

Here’s how one of our posts looks when shared on Facebook with Open Graph meta tags:

What are Open Graph meta tags?

Open Graph meta tags are snippets of code that control how URLs are displayed when shared on social media. 

They’re part of Facebook’s Open Graph protocol and are also used by other social media sites, including LinkedIn and Twitter (if Twitter Cards are absent).

You can find them in the <head> section of a webpage. Any tags with og: before a property name are Open Graph tags.

How to Restore from a QuiteRSS Backup

Like any good IT user, every month or so I make a backup of QuiteRSS (Via File –> Create Backup on the menu bar) from inside the program just in case I need it later.

When you make a backup, the program creates two files. Depending on the date of your backup, they’ll look like this – QuiteRss.ini_2015-08-03_07-57-56.bak and feeds.db_2015-08-03_07-57-56.bak.

Rename the two files created from the backup to QuiteRss.ini and feeds.db.

Close QuiteRSS before restoring the backup.

If you’re using Linux, open the terminal and then copy the files as shown below (substitute your user name for “thomaspc”):

$ cp QuiteRss.ini /home/thomaspc/.config/QuiteRss/QuiteRss.ini
cp: overwrite ‘/home/thomaspc/.config/QuiteRss/QuiteRss.ini’? y

Hit y key and then the return key when it asks you for permission to overwrite the file.

Now it’s time to copy the feeds.db file.

$ cp feeds.db /home/thomaspc/.local/share/data/QuiteRss/QuiteRss/feeds.db
cp: overwrite ‘/home/thomaspc/.local/share/data/QuiteRss/QuiteRss/feeds.db’? y

Again, hit y key and then the return key when it asks you for permission to overwrite the feeds.db file.

Open QuiteRSS and you should see that the backup has been restored along with your customizations like “star” feeds etc.

Linux Mint Programs


















sudo add-apt-repository ppa:gezakovacs/ppa -y
sudo apt-get update
sudo apt-get install unetbootin -y
sudo add-apt-repository ppa:gezakovacs/ppa -y
sudo apt-get update
sudo apt-get install unetbootin -y

Preview function on panel icons accidentally disabled

Open System Settings in the main menu, go to Preferences, Applets, Window list, click on the gear icon on the right and in Display, enable “Show window thumbnails on hover”.

Install Metamorphose 2

This is the most advanced of all available bulk renamers. Metamorphose 2 binaries for Linux (deb and rpm) and Windows are available on SourceForge.

Because these binaries are pretty old (2011), you can grab the latest version source (which dates to August, 2015) from GitHub.

Ubuntu 15.10 and newer users can install the latest Metamorphose 2 by using the main WebUpd8 PPA:

sudo add-apt-repository ppa:nilarimogard/webupd8
sudo apt-get update
sudo apt-get install metamorphose2

Define a Specific Sidebar Using Custom Fields

Do you want to define the custom sidebar for specific posts by replacing the get_sidebar() function? While there can be no plugin to achieve this, we have created a quick code snippet that you can use to define a specific sidebar using custom field in WordPress.


All you have to do is add this code to your theme’s template file where you want to call the custom sidebar:

$sidebar = get_post_meta($post->ID, "sidebar", true);

Note: If this is your first time adding code snippets in WordPress, then please refer to our guide on how to properly add code snippets in WordPress, so you don’t accidentally break your site.

If you liked this code snippet, please consider checking out our other articles on the site like: 62 best free WordPress blog themes and how to set up download tracking in WordPress with Google Analytics.

Generate WordPress theme templates with Underscores Components

You might already know about Underscores, often abbreviated as _s, which is a popular starter theme for WordPress. This is a big project maintained by Automattic which is the company operating WordPress.

Recently they created another tool called Components. This is a free online theme generator built on WordPress with custom blueprints made for portfolios, business sites, and different blog themes from standard blogs to magazines.

Components is completely free to use and it’s one of the most powerful generators on the web. Why start a new theme from scratch when you can work with the proven Underscores framework?

Each theme comes with a responsive layout, pre-built menus, and Sass code along with raw CSS.

You just need to select which template you want and give it a name (for example “My Theme”). Other optional info can include the theme’s slug, the author’s name/URI, and a brief description of the theme.

But with just a theme name you can download a complete package with a basic Underscores WP theme ready to go.

Naturally you can customize all of these themes to your liking and they’re pretty simple to work with.

Some developers may prefer to work with their own codebase rather than relying on someone else’s. But if you need to get a project online fast there’s no better way to get moving than with a pre-built blueprint.

You can also find all the Components source code on GitHub along with the individual themes located by themselves. If you want a WordPress-approved theme blueprint then the Components generator is an excellent place to start.