Blog

WordPress Templates and the WordPress is_() Function

computer screen displaying website home page

The WordPress is_() function is a series of template functions tells you which type of page is being requested. For example, is_single() refers to a single post. Is_home() if the home page is being requested. Here is a list of the WordPress is_() functions and the requests they represent.

The different WordPress is_() Functions

Is_home() –The front page

Is_single()- A single post

Is_page()- A static or a standalone page

Is_author()- An author

Is_date()- A year,month, or day

Is_year()- A year

Is_month()-A month

Is_day() A day

Is_time() An hour, minute, or second; either

Is_archive()- A category, an author or a date

Is_search()- A search

Is_404()- A 404 page

Is_feed()- A syndication feed

The is_page(), is_single() and is_category() can accept an id, name or nickname. Using the is_page();

Is_category() if a caegory is being served

Is_category(2) if the category with the id of 2 is being served

Is_category(About Me) if the category is ‘About Me’

Is_category(about-me) if the category is nicknamed about me

Using the is_() Functions.

We can use the WordPress is_() functions to customize our templates for different query types. For example, One index.php template can provide a different look for each WordPress is_() function. You can easily use the WordPress is_() functions to form conditionals for the various request types and generate whatever markup you like for each of those conditionals.

However, do not overuse too many conditionals as they tend to make the template rather busy and stressful to read. Alternatively, we can use multiple templates instead of just one template. For example, if we diosplay a single post page and a file named single.php is present, this will be loaded instead of the index. This goes for a category, author, pages etcetera. If is_page() is true and page.php is present , page.php is loaded. For each WordPress is_() function, strip the ‘is_’ from the front and add “.php” to derive the name of the template that will be loaded if that WordPress is_() function evaluates to correct. You can provide as many templates as you may wish or can also revert to using index.php.

The WordPress is_() function and the query-to-template mapping provide control for template and theme designers over presentation whether it is through one template or multiple templates.



Scroll to top