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

I want one image in header.php to change for different pages.

The function in header.php looks like that:

  //change image to "Archives"
 //change image to "404"

Now, is it possible to check if page is the search page AND what's the search string AND how many posts were found?

So what I want to do is basically:

 //change image to "Search" AND echo %s
if(is_search_empty()): //yes I made this up
 //change image to "Nothing found" AND echo $

Is it even possible outside the search.php page loop?

share|improve this question
up vote 1 down vote accepted

Now, is it possible to check if page is the search page


AND what's the search string

is_search() AND print get_query_var( 's' )

AND how many posts were found?

is_search() AND print $GLOBALS['wp_query']->number_posts()

… or if you got a custom query…

$my_query = new WP_Query( array( /* whatever args */ ) );
is_search() AND print $my_query->number_posts()
share|improve this answer
Thank you, but checking how many posts were found still doesn't seem to work for me. I have standard if( have_posts() ) : loop in search.php and your first code returns Fatal error: Call to undefined method WP_Query::found_posts(). – Wordpressor Mar 4 '13 at 3:06
Try $GLOBALS['wp_query']->number_posts(). Have written it from the backside of my head and not sure what the method name is. – kaiser Mar 4 '13 at 3:59
$GLOBALS['wp_query']->have_posts() was the answer, thanks a lot, Franz! – Wordpressor Mar 4 '13 at 4:14

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.