
{"id":3511,"date":"2014-05-08T02:22:52","date_gmt":"2014-05-08T02:22:52","guid":{"rendered":"http:\/\/tapchicntt.com\/?p=3511"},"modified":"2014-05-08T02:22:52","modified_gmt":"2014-05-08T02:22:52","slug":"tu-dong-doi-ten-anh-theo-title-post-khi-upload","status":"publish","type":"post","link":"https:\/\/tapchicntt.com\/tu-dong-doi-ten-anh-theo-title-post-khi-upload\/","title":{"rendered":"T\u1ef1 \u0111\u1ed9ng \u0111\u1ed5i t\u00ean \u1ea3nh theo title post khi upload"},"content":{"rendered":"<p>Trong qu\u00e1 tr\u00ecnh SEO cho m\u1ed9t b\u00e0i vi\u1ebft th\u00ec ph\u1ea7n SEO cho h\u00ecnh \u1ea3nh c\u0169ng r\u1ea5t l\u00e0 quan tr\u1ecdng. Ngo\u00e0i vi\u1ec7c t\u1ed1i \u01b0u h\u00f3a k\u00edch th\u01b0\u1edbc, ch\u1ecdn \u1ea3nh \u0111\u1eb9p, \u1ea3nh ph\u00f9 h\u1ee3p v\u1edbi n\u1ed9i dung b\u00e0i vi\u1ebft th\u00ec t\u00ean c\u1ee7a \u1ea3nh c\u0169ng \u0111\u00f3ng g\u00f3p m\u1ed9t ph\u1ea7n kh\u00f4ng nh\u1ecf trong vi\u1ec7c th\u00e2n thi\u1ec7n v\u1edbi ng\u01b0\u1eddi \u0111\u1ecdc c\u0169ng nh\u01b0 Google bot.<!--more--><\/p>\n<p>C\u0169ng c\u00f3 m\u1ed9t s\u1ed1 plugin gi\u1ea3i quy\u1ebft v\u1ea5n \u0111\u1ec1 n\u00e0y, nh\u01b0ng c\u00e1 nh\u00e2n m\u00ecnh th\u00ec lu\u00f4n \u01b0u ti\u00ean cho vi\u1ec7c d\u00f9ng code v\u00e0 c\u1ee5 th\u1ec3 \u1edf \u0111\u00e2y l\u00e0 t\u00edch h\u1ee3p th\u1eb3ng v\u00e0o theme.<\/p>\n<p>C\u00e1c b\u1ea1n m\u1edf file <strong>function.php<\/strong> v\u00e0 ch\u00e8n \u0111o\u1ea1n code sau:<\/p>\n<pre class=\"brush: php; title: ; notranslate\" title=\"\">\r\n\r\nfunction wp_modify_uploaded_file_names($image_name) {\r\n \r\n    \/\/ Get the parent post ID, if there is one\r\n    if( isset($_GET&#x5B;'post_id']) ) {\r\n        $post_id = $_GET&#x5B;'post_id'];\r\n    } elseif( isset($_POST&#x5B;'post_id']) ) {\r\n        $post_id = $_POST&#x5B;'post_id'];\r\n    }\r\n \r\n    \/\/ Only do this if we got the post ID--otherwise they're probably in\r\n    \/\/  the media section rather than uploading an image from a post.\r\n    if(is_numeric($post_id)) {\r\n \r\n        \/\/ Get the post slug\r\n        $post_obj = get_post($post_id);\r\n        $post_slug = $post_obj-&gt;post_name;\r\n \r\n        \/\/ If we found a slug\r\n        if($post_slug) {\r\n \r\n            $random_number = rand(10000,99999);\r\n            $image_name&#x5B;'name'] = $post_slug . '-' . $random_number . '.jpg';\r\n \r\n        }\r\n \r\n    }\r\n \r\n    return $image_name;\r\n \r\n}\r\nadd_filter('wp_handle_upload_prefilter', 'wp_modify_uploaded_file_names', 1, 1);\r\n\r\n<\/pre>\n<p>\u1ede \u0111o\u1ea1n code tr\u00ean ngo\u00e0i vi\u1ec7c \u0111\u1ed5i t\u00ean \u1ea3nh theo slug c\u1ee7a title post th\u00ec n\u00f3 c\u00f2n g\u00e1n th\u00eam m\u1ed9t con s\u1ed1, c\u1ee5 th\u1ec3 s\u1ed1 n\u00e0y \u0111\u01b0\u1ee3c l\u1ea5y ng\u1eabu nhi\u00ean t\u1eeb 10000 \u0111\u1ebfn 99999. \u0110i\u1ec1u n\u00e0y r\u1ea5t c\u00f3 l\u1ee3i n\u1ebfu nh\u01b0 trong m\u1ed9t b\u00e0i vi\u1ebft m\u00e0 c\u00e1c b\u1ea1n c\u00f3 nhi\u1ec1u \u1ea3nh.<\/p>\n<p>Ch\u00fac c\u00e1c b\u1ea1n th\u00e0nh c\u00f4ng. <\/p>\n","protected":false},"excerpt":{"rendered":"<p>Trong qu\u00e1 tr\u00ecnh SEO cho m\u1ed9t b\u00e0i vi\u1ebft th\u00ec ph\u1ea7n SEO cho h\u00ecnh \u1ea3nh c\u0169ng r\u1ea5t l\u00e0 quan tr\u1ecdng. Ngo\u00e0i [&hellip;]<\/p>\n","protected":false},"author":6,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[143],"tags":[],"class_list":["post-3511","post","type-post","status-publish","format-standard","hentry","category-thu-thuat-wordpress"],"views":427,"_links":{"self":[{"href":"https:\/\/tapchicntt.com\/rest-api\/wp\/v2\/posts\/3511","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=3511"}],"version-history":[{"count":0,"href":"https:\/\/tapchicntt.com\/rest-api\/wp\/v2\/posts\/3511\/revisions"}],"wp:attachment":[{"href":"https:\/\/tapchicntt.com\/rest-api\/wp\/v2\/media?parent=3511"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/tapchicntt.com\/rest-api\/wp\/v2\/categories?post=3511"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/tapchicntt.com\/rest-api\/wp\/v2\/tags?post=3511"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}