
{"id":3454,"date":"2014-04-30T10:26:49","date_gmt":"2014-04-30T10:26:49","guid":{"rendered":"http:\/\/tapchicntt.com\/?p=3454"},"modified":"2025-04-14T10:27:22","modified_gmt":"2025-04-14T03:27:22","slug":"wordpress-bat-buoc-chon-anh-dai-dien-truoc-khi-xuat-ban-bai-viet-trong-wordpress","status":"publish","type":"post","link":"https:\/\/tapchicntt.com\/wordpress-bat-buoc-chon-anh-dai-dien-truoc-khi-xuat-ban-bai-viet-trong-wordpress\/","title":{"rendered":"[WordPress] B\u1eaft bu\u1ed9c ch\u1ecdn \u1ea2nh \u0110\u1ea1i Di\u1ec7n tr\u01b0\u1edbc khi xu\u1ea5t b\u1ea3n b\u00e0i vi\u1ebft trong WordPress"},"content":{"rendered":"\n<p>Th\u00f4ng th\u01b0\u1eddng, l\u00fac chu\u1ea9n b\u1ecb xu\u1ea5t b\u1ea3n b\u00e0i vi\u1ebft (<code>publish post<\/code>), ch\u00fang ta c\u00f3 th\u1ec3 ch\u00e8n ho\u1eb7c kh\u00f4ng ch\u00e8n h\u00ecnh l\u00e0m \u1ea3nh \u0111\u1ea1i di\u1ec7n cho b\u00e0i vi\u1ebft \u0111\u00f3 (<strong>Featured Image<\/strong>).<\/p>\n\n\n\n<p>Tuy nhi\u00ean n\u1ebfu v\u00ec m\u1ed9t l\u00fd do n\u00e0o \u0111\u00f3 m\u00e0 c\u00e1c b\u1ea1n lu\u00f4n mu\u1ed1n t\u00e1c gi\u1ea3 ph\u1ea3i ch\u1ecdn \u1ea3nh \u0111\u1ea1i di\u1ec7n (<strong>Featured Image<\/strong>) tr\u01b0\u1edbc khi xu\u1ea5t b\u1ea3n b\u00e0i vi\u1ebft th\u00ec ch\u1ec9 vi\u1ec7c copy \u0111o\u1ea1n code b\u00ean d\u01b0\u1edbi v\u00e0 d\u00e1n n\u00f3 v\u00e0o file <code>functions.php<\/code> l\u00e0 xong.<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: php; title: ; notranslate\" title=\"\">\nadd_action(&#039;save_post&#039;, &#039;tapchicntt_check_thumbnail&#039;);\nadd_action(&#039;admin_notices&#039;, &#039;tapchicntt_thumbnail_error&#039;);\nfunction tapchicntt_check_thumbnail($post_id) {\n    \/\/ change to any custom post type\n    if(get_post_type($post_id) != &#039;post&#039;)\n        return;\n    if ( !has_post_thumbnail( $post_id ) ) {\n        \/\/ set a transient to show the users an admin message\n        set_transient( &quot;has_post_thumbnail&quot;, &quot;no&quot; );\n        \/\/ unhook this function so it doesn&#039;t loop infinitely\n        remove_action(&#039;save_post&#039;, &#039;tapchicntt_check_thumbnail&#039;);\n        \/\/ update the post set it to draft\n        wp_update_post(array(&#039;ID&#039; =&gt; $post_id, &#039;post_status&#039; =&gt; &#039;draft&#039;));\n        add_action(&#039;save_post&#039;, &#039;tapchicntt_check_thumbnail&#039;);\n    } else {\n        delete_transient( &quot;has_post_thumbnail&quot; );\n    }\n}\nfunction tapchicntt_thumbnail_error()\n{\n    \/\/ check if the transient is set, and display the error message\n    if ( get_transient( &quot;has_post_thumbnail&quot; ) == &quot;no&quot; ) {\n        echo &quot;&lt;div id=&#039;message&#039; class=&#039;error&#039;&gt;&lt;p&gt;&lt;strong&gt;B\u1ea1n ph\u1ea3i ch\u1ecdn Featured Image. B\u00e0i vi\u1ebft c\u1ee7a b\u1ea1n \u0111\u01b0\u1ee3c l\u01b0u nh\u01b0ng s\u1ebd kh\u00f4ng th\u1ec3 xu\u1ea5t b\u1ea3n.&lt;\/strong&gt;&lt;\/p&gt;&lt;\/div&gt;&quot;;\n        delete_transient( &quot;has_post_thumbnail&quot; );\n    }\n}\n<\/pre><\/div>\n\n\n<p>V\u00e0 b\u00e2y gi\u1edd m\u1ed7i khi t\u00e1c gi\u1ea3 nh\u1ea5n n\u00fat &#8220;<strong>Publish<\/strong>&#8221; \u0111\u1ec3 xu\u1ea5t b\u1ea3n m\u00e0 ch\u01b0a ch\u1ecdn \u1ea3nh \u0111\u1ea1i di\u1ec7n (<strong>Featured Image<\/strong>) th\u00ec s\u1ebd xu\u1ea5t hi\u1ec7n th\u00f4ng b\u00e1o &#8220;<strong><em>B\u1ea1n ph\u1ea3i ch\u1ecdn Featured Image. B\u00e0i vi\u1ebft c\u1ee7a b\u1ea1n \u0111\u01b0\u1ee3c l\u01b0u nh\u01b0ng s\u1ebd kh\u00f4ng th\u1ec3 xu\u1ea5t b\u1ea3n.<\/em><\/strong>&#8220;.<\/p>\n\n\n\n<p>R\u1ea5t tuy\u1ec7t ph\u1ea3i kh\u00f4ng c\u00e1c b\u1ea1n.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Th\u00f4ng th\u01b0\u1eddng, l\u00fac chu\u1ea9n b\u1ecb xu\u1ea5t b\u1ea3n b\u00e0i vi\u1ebft (publish post), ch\u00fang ta c\u00f3 th\u1ec3 ch\u00e8n ho\u1eb7c kh\u00f4ng ch\u00e8n h\u00ecnh [&hellip;]<\/p>\n","protected":false},"author":6,"featured_media":6979,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[143],"tags":[],"class_list":["post-3454","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-thu-thuat-wordpress"],"views":428,"_links":{"self":[{"href":"https:\/\/tapchicntt.com\/rest-api\/wp\/v2\/posts\/3454","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/tapchicntt.com\/rest-api\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/tapchicntt.com\/rest-api\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/tapchicntt.com\/rest-api\/wp\/v2\/users\/6"}],"replies":[{"embeddable":true,"href":"https:\/\/tapchicntt.com\/rest-api\/wp\/v2\/comments?post=3454"}],"version-history":[{"count":1,"href":"https:\/\/tapchicntt.com\/rest-api\/wp\/v2\/posts\/3454\/revisions"}],"predecessor-version":[{"id":9626,"href":"https:\/\/tapchicntt.com\/rest-api\/wp\/v2\/posts\/3454\/revisions\/9626"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/tapchicntt.com\/rest-api\/wp\/v2\/media\/6979"}],"wp:attachment":[{"href":"https:\/\/tapchicntt.com\/rest-api\/wp\/v2\/media?parent=3454"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/tapchicntt.com\/rest-api\/wp\/v2\/categories?post=3454"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/tapchicntt.com\/rest-api\/wp\/v2\/tags?post=3454"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}