• Kushal Jayswal is a frontend developer from India. His expertise includes HTML5, CSS3, Sass, LESS, Responsive Web Design, JavaScript, jQuery, Twitter Bootstrap, Material Design, AngularJS, NodeJS, WordPress and Liferay Theming. He has founded TeckStack.com in 2011 to share his frontend knowledge with the community. His core interests focus on frontend, blogging, UI, UX and many others. He loves to talk on trending frontend technologies and successful blogging.

WordPress - Singular Vs. Single

WordPress

The WordPress Codex has very well documented for developers. However, there are few things you'll only face, while come to certain situation. There are many conditional tags in WordPress but some tags remain confusing to understand by their names. This article will focus on the difference between is_singular() and is_single().

First, let's understand the terms and then we will see an example.

The Difference

  • is_singular() targets all templates with content-{something}.php files name in a theme. So if you have some code to manipulate with all single pages, then you should use is_singular().
  • On the other hand is_single() targets only single.php template, which meant to target only a single post page.

An Example

For an example, you want to add social share icons without using a plugin. Below are some requirement:

  • Icons should be visible for index.php, archive.php and single.php templates.
  • Icons should not come for the page.php template.

Here we have two options:

  1. We can directly put conditional check with if( !is_page() ) for a function inside functions.php file or
  2. We have to use multiple conditional check as per below snippet
function someName($content) {
    if( is_single() || is_home() || is_archive() || is_search() ){
        // custom code...
    }
}

Learning is everything. If you think there are still something you can add - kindly comment below.

Resources