{"id":1343,"date":"2021-07-23T07:20:33","date_gmt":"2021-07-23T12:20:33","guid":{"rendered":"https:\/\/www.knownhost.com\/kb\/?p=1343"},"modified":"2023-03-10T12:39:45","modified_gmt":"2023-03-10T18:39:45","slug":"what-are-conditional-tags-in-wordpress-comments","status":"publish","type":"post","link":"https:\/\/www.knownhost.com\/kb\/what-are-conditional-tags-in-wordpress-comments\/","title":{"rendered":"What are Conditional Tags in WordPress Comments?"},"content":{"rendered":"<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_82_2 ez-toc-wrap-right counter-hierarchy ez-toc-counter ez-toc-custom ez-toc-container-direction\">\n<div class=\"ez-toc-title-container\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">Table of Contents<\/p>\n<span class=\"ez-toc-title-toggle\"><a href=\"#\" class=\"ez-toc-pull-right ez-toc-btn ez-toc-btn-xs ez-toc-btn-default ez-toc-toggle\" aria-label=\"Toggle Table of Content\"><span class=\"ez-toc-js-icon-con\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #212121;color:#212121\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #212121;color:#212121\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/span><\/a><\/span><\/div>\n<nav><ul class='ez-toc-list ez-toc-list-level-1 eztoc-toggle-hide-by-default' ><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/www.knownhost.com\/kb\/what-are-conditional-tags-in-wordpress-comments\/#is_comments_popup\" >is_comments_popup()<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/www.knownhost.com\/kb\/what-are-conditional-tags-in-wordpress-comments\/#comments_open\" >comments_open()<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/www.knownhost.com\/kb\/what-are-conditional-tags-in-wordpress-comments\/#is_the_query_for_a_comments_feed\" >Is the query for a comments feed?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/www.knownhost.com\/kb\/what-are-conditional-tags-in-wordpress-comments\/#are_there_comments_to_loop_through\" >Are there comments to loop through?<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/www.knownhost.com\/kb\/what-are-conditional-tags-in-wordpress-comments\/#conclusion\" >Conclusion<\/a><\/li><\/ul><\/nav><\/div>\n\n<p>WordPress has a number of conditional tags that evaluate whether something is true or false, then based on the logical value, does one thing or another. Generally, if something is true take action, otherwise do not, then return to whatever it was doing.<\/p>\n\n\n\n<p>A simple example of a conditional tag in WordPress would be to check if someone has visited the homepage, and if so, they<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;?php\n  if ( is_home()) {\n    echo \"You have reached the home page\";\n  }\n?&gt;<\/code><\/pre>\n\n\n\n<p>There aren\u2019t that many conditional tags surrounding comments in WordPress, but there are a couple.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"is_comments_popup\"><span class=\"ez-toc-section\" id=\"is_comments_popup\"><\/span>is_comments_popup()<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>This returns true if you\u2019re inside a WordPress comments <a href=\"https:\/\/developer.wordpress.org\/reference\/functions\/comments_popup_link\/\">popup<\/a> and can be used as:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>  &lt;?php is_comments_popup(); ?&gt;<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"comments_open\"><span class=\"ez-toc-section\" id=\"comments_open\"><\/span>comments_open()<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>This returns true if comments are enabled for a particular post id:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>  &lt;?php comments_open( $post_id ); ?&gt;<\/code><\/pre>\n\n\n\n<p>In addition to the conditional tags that operate directly on comments, there are a number of conditionals that work through other sections of the code, such as the $wp_query. Within the query, one can check if the query is dealing with a comment feed or whether there are comments to loop through.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"is_the_query_for_a_comments_feed\"><span class=\"ez-toc-section\" id=\"is_the_query_for_a_comments_feed\"><\/span>Is the query for a comments feed?<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>If the query is for a comments feed, return true. Note that you have to run the query before checking, otherwise the query will always return false:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>  function is_comment_feed() {\n    global $wp_query;\n    if ( ! isset( $wp_query ) ) {\n      _doing_it_wrong( __FUNCTION__, __( 'Conditional query tags do not\n                                          work before the query is run. Before then,\n                                          they always return false.' ), '3.1.0' );\n      return false;\n    }\n    return $wp_query-&gt;is_comment_feed();\n  }<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"are_there_comments_to_loop_through\"><span class=\"ez-toc-section\" id=\"are_there_comments_to_loop_through\"><\/span>Are there comments to loop through?<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>If there are comments, return true, otherwise false.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>  function have_comments() {\n    global $wp_query;\n    return $wp_query-&gt;have_comments();\n  }<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"conclusion\"><\/span>Conclusion<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>Have a WordPress website? Check out our <a href=\"https:\/\/www.knownhost.com\/wordpress-hosting\"><strong>Managed Hosting for WordPress<\/strong><\/a> and see if we are a good fit for you. <strong><a href=\"https:\/\/www.knownhost.com\">KnownHost <\/a><\/strong>offers 365 days a year, 24 hours a day, all 7 days of the week best in class technical support. A dedicated team ready to help you should you need our assistance. You\u2019re not using KnownHost for the best webhosting experience? Well, why not?<\/p>\n","protected":false},"excerpt":{"rendered":"<p>WordPress has a number of conditional tags that evaluate whether something is true or false, then based on the logical value, does one thing or another. Generally, if something is true take action, otherwise do not, then return to whatever it was doing. A simple example of a conditional tag in WordPress would be to [&hellip;]<\/p>\n","protected":false},"author":4,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[146],"tags":[251,252,106],"class_list":["post-1343","post","type-post","status-publish","format-standard","hentry","category-wordpress","tag-blogs","tag-cms","tag-wordpress"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.5 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>What are Conditional Tags in WordPress Comments? - KnownHost<\/title>\n<meta name=\"description\" content=\"In this article we explain about WordPress Comments conditional tags and how to activate them on your blog.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.knownhost.com\/kb\/what-are-conditional-tags-in-wordpress-comments\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"What are Conditional Tags in WordPress Comments? - KnownHost\" \/>\n<meta property=\"og:description\" content=\"In this article we explain about WordPress Comments conditional tags and how to activate them on your blog.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.knownhost.com\/kb\/what-are-conditional-tags-in-wordpress-comments\/\" \/>\n<meta property=\"og:site_name\" content=\"KnownHost\" \/>\n<meta property=\"article:published_time\" content=\"2021-07-23T12:20:33+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2023-03-10T18:39:45+00:00\" \/>\n<meta name=\"author\" content=\"Jonathan K. W.\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Jonathan K. W.\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.knownhost.com\\\/kb\\\/what-are-conditional-tags-in-wordpress-comments\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.knownhost.com\\\/kb\\\/what-are-conditional-tags-in-wordpress-comments\\\/\"},\"author\":{\"name\":\"Jonathan K. W.\",\"@id\":\"https:\\\/\\\/www.knownhost.com\\\/kb\\\/#\\\/schema\\\/person\\\/3db6e20d1f33519cd68fe0ba1230a48b\"},\"headline\":\"What are Conditional Tags in WordPress Comments?\",\"datePublished\":\"2021-07-23T12:20:33+00:00\",\"dateModified\":\"2023-03-10T18:39:45+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.knownhost.com\\\/kb\\\/what-are-conditional-tags-in-wordpress-comments\\\/\"},\"wordCount\":288,\"keywords\":[\"blogs\",\"cms\",\"wordpress\"],\"articleSection\":[\"WordPress\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.knownhost.com\\\/kb\\\/what-are-conditional-tags-in-wordpress-comments\\\/\",\"url\":\"https:\\\/\\\/www.knownhost.com\\\/kb\\\/what-are-conditional-tags-in-wordpress-comments\\\/\",\"name\":\"What are Conditional Tags in WordPress Comments? - KnownHost\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.knownhost.com\\\/kb\\\/#website\"},\"datePublished\":\"2021-07-23T12:20:33+00:00\",\"dateModified\":\"2023-03-10T18:39:45+00:00\",\"author\":{\"@id\":\"https:\\\/\\\/www.knownhost.com\\\/kb\\\/#\\\/schema\\\/person\\\/3db6e20d1f33519cd68fe0ba1230a48b\"},\"description\":\"In this article we explain about WordPress Comments conditional tags and how to activate them on your blog.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.knownhost.com\\\/kb\\\/what-are-conditional-tags-in-wordpress-comments\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.knownhost.com\\\/kb\\\/what-are-conditional-tags-in-wordpress-comments\\\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.knownhost.com\\\/kb\\\/what-are-conditional-tags-in-wordpress-comments\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.knownhost.com\\\/kb\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"What are Conditional Tags in WordPress Comments?\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.knownhost.com\\\/kb\\\/#website\",\"url\":\"https:\\\/\\\/www.knownhost.com\\\/kb\\\/\",\"name\":\"KnownHost\",\"description\":\"KnownHost provides a comprehensive webhosting knowledge base to help answer many of your common webhosting and linux questions.\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.knownhost.com\\\/kb\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.knownhost.com\\\/kb\\\/#\\\/schema\\\/person\\\/3db6e20d1f33519cd68fe0ba1230a48b\",\"name\":\"Jonathan K. W.\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/f432b99e6651fe8d1deb57a285bd84e806f1c9ae8b4c6c585d7e3a0b33789ad9?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/f432b99e6651fe8d1deb57a285bd84e806f1c9ae8b4c6c585d7e3a0b33789ad9?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/f432b99e6651fe8d1deb57a285bd84e806f1c9ae8b4c6c585d7e3a0b33789ad9?s=96&d=mm&r=g\",\"caption\":\"Jonathan K. W.\"},\"sameAs\":[\"https:\\\/\\\/www.knownhost.com\"]}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"What are Conditional Tags in WordPress Comments? - KnownHost","description":"In this article we explain about WordPress Comments conditional tags and how to activate them on your blog.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.knownhost.com\/kb\/what-are-conditional-tags-in-wordpress-comments\/","og_locale":"en_US","og_type":"article","og_title":"What are Conditional Tags in WordPress Comments? - KnownHost","og_description":"In this article we explain about WordPress Comments conditional tags and how to activate them on your blog.","og_url":"https:\/\/www.knownhost.com\/kb\/what-are-conditional-tags-in-wordpress-comments\/","og_site_name":"KnownHost","article_published_time":"2021-07-23T12:20:33+00:00","article_modified_time":"2023-03-10T18:39:45+00:00","author":"Jonathan K. W.","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Jonathan K. W.","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.knownhost.com\/kb\/what-are-conditional-tags-in-wordpress-comments\/#article","isPartOf":{"@id":"https:\/\/www.knownhost.com\/kb\/what-are-conditional-tags-in-wordpress-comments\/"},"author":{"name":"Jonathan K. W.","@id":"https:\/\/www.knownhost.com\/kb\/#\/schema\/person\/3db6e20d1f33519cd68fe0ba1230a48b"},"headline":"What are Conditional Tags in WordPress Comments?","datePublished":"2021-07-23T12:20:33+00:00","dateModified":"2023-03-10T18:39:45+00:00","mainEntityOfPage":{"@id":"https:\/\/www.knownhost.com\/kb\/what-are-conditional-tags-in-wordpress-comments\/"},"wordCount":288,"keywords":["blogs","cms","wordpress"],"articleSection":["WordPress"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/www.knownhost.com\/kb\/what-are-conditional-tags-in-wordpress-comments\/","url":"https:\/\/www.knownhost.com\/kb\/what-are-conditional-tags-in-wordpress-comments\/","name":"What are Conditional Tags in WordPress Comments? - KnownHost","isPartOf":{"@id":"https:\/\/www.knownhost.com\/kb\/#website"},"datePublished":"2021-07-23T12:20:33+00:00","dateModified":"2023-03-10T18:39:45+00:00","author":{"@id":"https:\/\/www.knownhost.com\/kb\/#\/schema\/person\/3db6e20d1f33519cd68fe0ba1230a48b"},"description":"In this article we explain about WordPress Comments conditional tags and how to activate them on your blog.","breadcrumb":{"@id":"https:\/\/www.knownhost.com\/kb\/what-are-conditional-tags-in-wordpress-comments\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.knownhost.com\/kb\/what-are-conditional-tags-in-wordpress-comments\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.knownhost.com\/kb\/what-are-conditional-tags-in-wordpress-comments\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.knownhost.com\/kb\/"},{"@type":"ListItem","position":2,"name":"What are Conditional Tags in WordPress Comments?"}]},{"@type":"WebSite","@id":"https:\/\/www.knownhost.com\/kb\/#website","url":"https:\/\/www.knownhost.com\/kb\/","name":"KnownHost","description":"KnownHost provides a comprehensive webhosting knowledge base to help answer many of your common webhosting and linux questions.","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.knownhost.com\/kb\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/www.knownhost.com\/kb\/#\/schema\/person\/3db6e20d1f33519cd68fe0ba1230a48b","name":"Jonathan K. W.","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/f432b99e6651fe8d1deb57a285bd84e806f1c9ae8b4c6c585d7e3a0b33789ad9?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/f432b99e6651fe8d1deb57a285bd84e806f1c9ae8b4c6c585d7e3a0b33789ad9?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/f432b99e6651fe8d1deb57a285bd84e806f1c9ae8b4c6c585d7e3a0b33789ad9?s=96&d=mm&r=g","caption":"Jonathan K. W."},"sameAs":["https:\/\/www.knownhost.com"]}]}},"_links":{"self":[{"href":"https:\/\/www.knownhost.com\/kb\/wp-json\/wp\/v2\/posts\/1343","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.knownhost.com\/kb\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.knownhost.com\/kb\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.knownhost.com\/kb\/wp-json\/wp\/v2\/users\/4"}],"replies":[{"embeddable":true,"href":"https:\/\/www.knownhost.com\/kb\/wp-json\/wp\/v2\/comments?post=1343"}],"version-history":[{"count":0,"href":"https:\/\/www.knownhost.com\/kb\/wp-json\/wp\/v2\/posts\/1343\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.knownhost.com\/kb\/wp-json\/wp\/v2\/media?parent=1343"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.knownhost.com\/kb\/wp-json\/wp\/v2\/categories?post=1343"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.knownhost.com\/kb\/wp-json\/wp\/v2\/tags?post=1343"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}