Find out in this tutorial how to display an icon in the top WordPress admin bar to warn you if the site has indexing disabled.
One of the worst mistakes you can make when creating a new site or moving to production from staging is to leave the “Discourage search engines from indexing this site” checkbox selected (located in Settings > Reading).
In a previous tutorial I showed you a way to avoid this by defining WordPress development environment.
But today I bring you a complementary option that will visually “tell you” whenever a site has the “Discourage search engines from indexing this site” checkbox selected.
This is the final result:

Interested? Here’s how to get it:
Snippet to insert a warning in WordPress admin bar if indexing is disabled.
Add the following code at the end of functions.php or in your functionality plugin:
To see this and another 919 code snippets of this website, login or subscribe here.
It’s that simple.
In this case you use the admin_bar_menu
hook in combination with the blog_public
parameter to display or not display an icon in the top WordPress admin bar.
If the “Discourage search engines from indexing this site” checkbox is selected, a red crossed-out eye icon (which you can change) will be displayed as a warning.
Hovering your mouse over the icon will display a notice explaining the reason for the warning (which you can edit).
And if you click on it it will take you directly to Settings > Reading, so you can uncheck the box.

Is the checkbox unchecked? Then you won’t see any warning. Everything is fine (well, at least the indexing). 😅
Conclusion
With a few lines of code you can get an icon to show up in the WordPress admin bar that warns you if indexing is disabled on the site.
Any questions? I read you in the comments.
And if you want to give me any suggestion for future tutorials, leave it in the contact form. Advantages of being a subscriber. 😉