

Returns true when Post 17 is considered a sticky post. In this example, no post ID argument is given, so the post ID for the Loop post is used. Returns true if the “Stick this post to the front page” check box has been checked for the current post. Returns true for any is_single, is_page, and is_attachment. Presumably the same holds for a post with the slug “17”. A post named “17” would be displayed if a post ID of 17 was requested. Note: This function does not distinguish between the post ID, post title, or post name. Returns true when the single post being displayed is either the post_title is “Beef Stew”, post_title is “Pea Soup” or post_title is “Chilli”. Is_single( array( ‘Beef Stew’, ‘Pea Soup’, ‘Chilli’ ) ) Returns true when the single post being displayed is either the post_name “beef-stew”, post_name “pea-soup” or post_name “chilli”.

Is_single( array( ‘beef-stew’, ‘pea-soup’, ‘chilli’ ) ) Returns true when the single post being displayed is either post ID = 17, post ID = 19, post ID = 1 or post ID = 11. Returns true when the single post being displayed is either post ID 17, or the post_name is “beef-stew”, or the post_title is “Irish Stew”.

Is_single( array( 17, ‘beef-stew’, ‘Irish Stew’ ) ) Proves true when the Post with Post Slug “beef-stew” is being displayed as a single Post. In this case, it proves true when the Post with title “Irish Stew” is being displayed as a single Post. The above example proves true when Post 17 is being displayed as a single Post. Is_single() can also check for certain posts by ID and other parameters. This condition returns false if you are on a page. Returns true when any single Post (or attachment, or custom Post Type) is being displayed. This condition returns true when the Dashboard or the administration panels are being displayed.
Php if else code#
If it’s false, the first set of code is skipped, and the second set of code (after the else) is executed instead.įor example, you could ask if a user is logged in, and then provide a different greeting depending on the result.

If the statement is found to be true, the first set of code is executed. The code begins by checking to see if a statement is true or false. Conditional Tags usually work with PHP if / else Conditional Statements. They tell WordPress what code to display under specific conditions.
