WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Is it possible to return a custom message if the tag search returns empty?

On my menu i have a link as: www.domain.com/tag/example

I don't want to remove the link but also it's a bit annoying if the user presses on this and he sees a blank page. At least a message "sorry there no results for this tag" would do!

many thanks Andy

share|improve this question

I am concerned about one part of your description. You say the user sees a "blank" page. Is the page completely blank? If so, you have a fatal error somewhere and an empty tag Loop isn't the problem. I am assuming you meant that the content is empty but otherwise the page loads fine.

You need to find the Loop for the page that displays the tags. The most likely candidates are index.php or tag.php but that is not an exhaustive list. In that file there should be something like:

if (have_posts()) {
  while(have_posts()) {
   // code to display the post

Add an else:

if (have_posts()) {
  while(have_posts()) {
   // code to display the post
} else {
  echo 'no post in that tag';

You need to make sure that your else echoes markup matching the Loop markup or you won't have consistent formatting.

Based on the limited information in your question that is the best answer I've got.

share|improve this answer
isn't wordpress will bypass tag.php if the requested tag didn't exist? – bangbambang Feb 7 '13 at 1:19
@bangbambang , not when I try it. – s_ha_dum Feb 7 '13 at 1:48

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.