WordPress Conditional Tags


/ Published in: PHP
Save to your folder(s)

Reference for WordPress conditional tags with code example.


Copy this code and paste it in your HTML
  1. if ( comments_open() ) {
  2. // When comments are allowed
  3. } elseif ( has_excerpt() ) {
  4. // When the current post has an excerpt
  5. } elseif ( has_tag() ) {
  6. // When the current post has a tag
  7. } elseif ( in_category('n') ) {
  8. // Returns true if the current post is in the specified category 'n'
  9. } elseif ( is_404() ) {
  10. // When a "HTTP 404: Not Found" error occurs
  11. } elseif ( is_admin() ) {
  12. // When the Dashboard or the administration panels are being displayed
  13. } elseif ( is_archive() ) {
  14. // When any type of Archive page is being displayed
  15. } elseif ( is_attachment() ) {
  16. // When an attachment document to a post or Page is being displayed
  17. } elseif ( is_author() ) {
  18. // When any Author page is being displayed
  19. } elseif ( is_category() ) {
  20. // When any Category archive page is being displayed
  21. } elseif ( is_comments_popup() ) {
  22. // When in Comments Popup window
  23. } elseif ( is_date() ) {
  24. // When any date-based archive page is being displayed
  25. } elseif ( is_day() ) {
  26. // When a daily archive is being displayed
  27. } elseif ( is_feed() ) {
  28. // When the site requested is a Syndication
  29. } elseif ( is_front_page() ) {
  30. // When it is the front of the site displayed
  31. } elseif ( is_home() ) {
  32. // When it is the front of the site displayed
  33. } elseif ( is_month() ) {
  34. // When a monthly archive is being displayed
  35. } elseif ( is_page() ) {
  36. // When any Page is being displayed
  37. } elseif ( is_page_template() ) {
  38. // Is a Page Template being used
  39. } elseif ( is_paged() ) {
  40. // When the page being displayed is "paged"
  41. } elseif ( is_preview() ) {
  42. // When a single post being displayed is viewed in Draft mode
  43. } elseif ( is_search() ) {
  44. // When a search result page archive is being displayed
  45. } elseif ( is_single() ) {
  46. // When any single Post (or attachment, or custom Post Type) page is being displayed
  47. } elseif ( is_singular() ) {
  48. // When any of the following return true: is_single(), is_page() or is_attachment()
  49. } elseif ( is_sticky() ) {
  50. // Returns true if "Stick this post to the front page" check box has been checked for the current post
  51. } elseif ( is_tag() ) {
  52. // When any Tag archive page is being displayed
  53. } elseif ( is_tax() ) {
  54. // When any Taxonomy archive page is being displayed
  55. } elseif ( is_time() ) {
  56. // When an hourly, "minutely", or "secondly" archive is being displayed
  57. } elseif ( is_trackback() ) {
  58. // When the site requested is WordPress' hook into its Trackback engine
  59. } elseif ( is_year() ) {
  60. // When a yearly archive is being displayed
  61. } elseif ( pings_open () ) {
  62. // When pings are allowed for the current Post
  63. }

URL: http://codex.wordpress.org/Conditional_Tags

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.