On my WordPress theme, How can I find which page is being requested by the visitor?

So you want to know if the visitor is viewing the homepage, a category or a page? WordPress have easy functions for that:

  • is_home() : returns true if the visitor is viewing your blog homepage
  • is_category() : returns true if viewing a category archive
  • is_category(‘3’) : returns true if viewing the archive of the category with the id 3
  • is_category(‘People and society’): return true if viewing the archive of the category with the name People and society
  • is_category(‘people-society’): return true if viewing the archive of the category with the slug people-society

These are the most used and you can find a lot more on the WordPress Codex.