{"id":4263,"date":"2018-08-16T14:47:20","date_gmt":"2018-08-16T18:47:20","guid":{"rendered":"https:\/\/themespress.ca\/?p=4263"},"modified":"2021-11-18T06:58:48","modified_gmt":"2021-11-18T11:58:48","slug":"disabling-comments-on-your-blog","status":"publish","type":"post","link":"https:\/\/themespress.ca\/en\/disabling-comments-on-your-blog\/","title":{"rendered":"Disabling Comments on your Blog"},"content":{"rendered":"<div class=\"wpb-content-wrapper\"><div class=\"vc_row wpb_row vc_row-fluid\"><div class=\"wpb_column vc_column_container vc_col-sm-12\"><div class=\"vc_column-inner\"><div class=\"wpb_wrapper\">\n\t<div class=\"wpb_text_column wpb_content_element\" >\n\t\t<div class=\"wpb_wrapper\">\n\t\t\t<p>With this tutorial, we will show you a function that allows you to disabled or tweak comments left on your website by users. The function users the <a href=\"https:\/\/codex.wordpress.org\/Function_Reference\/comments_open\" target=\"_blank\" rel=\"noopener noreferrer\">comments_open<\/a> filter.<\/p>\n<p>Here&#8217;s the function for the condition: <strong>$post = get_post( $post_id );<\/strong> and if <strong>$post-&gt;post_type<\/strong> correspond \u00e0 post (which is the default post type for articles\/posts), then the $open variable must return <strong>false<\/strong>.<\/p>\n\n\t\t<\/div>\n\t<\/div>\n<h2 style=\"text-align: left\" class=\"vc_custom_heading vc_do_custom_heading\" >Disabling comments on your blog<\/h2><div id=\"ts-enlighterjs-container-2596106\" class=\"ts-enlighterjs-container-single-enabled  \" style=\"width: 100%;  margin-top: 0px; margin-bottom: 0px;\" data-enlighter-doubleclick=\"true\" data-enlighter-windowbutton=\"true\" data-enlighter-windowtext=\"New Window\" data-enlighter-rawbutton=\"true\" data-enlighter-rawtext=\"RAW Code\" data-enlighter-infobutton=\"false\" data-enlighter-infotext=\"EnlighterJS\" data-enlighter-indent=\"2\"><pre id=\"ts-enlighterjs-pre-2596106\" class=\"\" style=\"white-space: pre-wrap; height: 100%; margin: 0; padding: 0;\" data-enlighter-language=\"php\" data-enlighter-theme=\"enlighter\" data-enlighter-group=\"\" data-enlighter-title=\"\" data-enlighter-linenumbers=\"true\" data-enlighter-lineoffset=\"1\" data-enlighter-highlight=\"\">add_filter(&#039;comments_open&#039;, &#039;lenomdemafonction&#039;, 10, 2);\nfunction lenomdemafonction( $open, $post_id ) {\n$post = get_post( $post_id );\nif (&#039;post&#039; == $post-&amp;gt;post_type)\n$open = false;\nreturn $open;\n}<\/pre><\/div>\n\t<div class=\"wpb_text_column wpb_content_element\" >\n\t\t<div class=\"wpb_wrapper\">\n\t\t\t<p>We could also disable comments on your pages only; simply replace <strong>&#8216;post&#8217;<\/strong> by <strong>&#8216;page&#8217;<\/strong>. For post types, simply had the post title instead of &#8216;post&#8217;.<\/p>\n<p>Don&#8217;t forget that under Discussion settings, the option <strong>that allows users to leaves comments<\/strong> must be left unchecked.<\/p>\n\n\t\t<\/div>\n\t<\/div>\n<\/div><\/div><\/div><\/div>\n<\/div>","protected":false},"excerpt":{"rendered":"With this tutorial, we will show you a function that allows you to disabled or tweak comments left on your website by users. The function users the comments_open filter. Here's<div class=\"read-more\"><a class=\"btn button-secondary\" href=\"https:\/\/themespress.ca\/en\/disabling-comments-on-your-blog\/\">Read More<\/a><\/div>","protected":false},"author":81,"featured_media":4960,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"inline_featured_image":false,"footnotes":""},"categories":[283],"tags":[],"class_list":["post-4263","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-tutorials"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/themespress.ca\/en\/wp-json\/wp\/v2\/posts\/4263","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/themespress.ca\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/themespress.ca\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/themespress.ca\/en\/wp-json\/wp\/v2\/users\/81"}],"replies":[{"embeddable":true,"href":"https:\/\/themespress.ca\/en\/wp-json\/wp\/v2\/comments?post=4263"}],"version-history":[{"count":0,"href":"https:\/\/themespress.ca\/en\/wp-json\/wp\/v2\/posts\/4263\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/themespress.ca\/en\/wp-json\/wp\/v2\/media\/4960"}],"wp:attachment":[{"href":"https:\/\/themespress.ca\/en\/wp-json\/wp\/v2\/media?parent=4263"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/themespress.ca\/en\/wp-json\/wp\/v2\/categories?post=4263"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/themespress.ca\/en\/wp-json\/wp\/v2\/tags?post=4263"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}