{"id":3920,"date":"2026-01-01T01:55:51","date_gmt":"2026-01-01T01:55:51","guid":{"rendered":"https:\/\/cachsudung.com\/?p=3920"},"modified":"2026-01-01T01:55:51","modified_gmt":"2026-01-01T01:55:51","slug":"code-tu-dong-luu-anh-vao-hot","status":"publish","type":"post","link":"https:\/\/how.congdongso.net\/en\/the-code-from-the-same-link-saves-you-in-hot\/","title":{"rendered":"Code to automatically save images to hot when copying images from other pages"},"content":{"rendered":"<div>\n<p style=\"text-align: justify;\"><strong><a href=\"https:\/\/how.congdongso.net\/wordpress\/code-tu-dong-luu-anh-vao-hot\/\">Code to automatically save images to hot when copying images from other pages<\/a><\/strong>. This feature helps automatically save images that you have copied from another website to the hot folder on your computer.<\/p>\n<p style=\"text-align: justify;\">When you copy an image from the website, the code will automatically recognize the copying of the image and save it to the hot folder you specified earlier. This makes it easy to organize and quickly access images you&#039;ve copied from the web without having to save them manually.<\/p>\n<p style=\"text-align: justify;\">You can also find more content in <a href=\"https:\/\/how.congdongso.net\/wordpress\/code\/\" target=\"_blank\" rel=\"noopener\"><strong>good code<\/strong><\/a> or <a href=\"https:\/\/how.congdongso.net\/wordpress\/\" target=\"_blank\" rel=\"noopener\"><strong>wordpress code<\/strong><\/a> ours<\/p>\n<h2 style=\"text-align: justify;\">Code to automatically save images to hot when copying images from other pages<\/h2>\n<p style=\"text-align: justify;\">This code is functional.<\/p>\n<ul style=\"text-align: justify;\">\n<li>1 as the title says it can automatically save images to our hotbox when we copy images from another page.<\/li>\n<li>Automatically rename files according to Seo standards when saving to your hotline<\/li>\n<\/ul>\n<p style=\"text-align: justify;\">For example, when copying another party&#039;s file name, it can be <strong>abcxyz.jpg<\/strong> Change the title of the article:<strong> title-de-bait-viet-xxx.jpg<\/strong><\/p>\n<p style=\"text-align: justify;\">In there <strong>xxx<\/strong> is a series of jumping numbers to avoid duplicates<\/p>\n<p style=\"text-align: justify;\">Experience: Let the code to automatically save images work effectively. You should give the article a title first and then copy the images and content. Now the code will automatically rename the file according to our title, which will be better for SEO<\/p>\n<p style=\"text-align: justify;\"><strong>Note:<\/strong> This code is used to execute on PHP or WordPress website platform<\/p>\n<ul>\n<li><strong><a href=\"https:\/\/how.congdongso.net\/dich-vu-thiet-ke-website-chuan-seo\/\" target=\"_blank\" rel=\"noopener\">Website design service according to SEO standards, good conversion<\/a><\/strong><\/li>\n<li><strong><a href=\"https:\/\/how.congdongso.net\/dich-vu-quan-tri-website\/\" target=\"_blank\" rel=\"noopener\">Website management services effectively take care of websites<\/a><\/strong><\/li>\n<li><strong><a href=\"https:\/\/how.congdongso.net\/dich-vu-thiet-ke-do-hoa\/\" target=\"_blank\" rel=\"noopener\">Learn about graphic design services<\/a><\/strong><\/li>\n<\/ul>\n<h2 style=\"text-align: justify;\">The steps to insert code to automatically save images to hot are as follows.<\/h2>\n<h3 style=\"text-align: justify;\">Step 1: Log in to your account<\/h3>\n<p style=\"text-align: justify;\">You need to log in to an account with administrator rights to use it<\/p>\n<h3 style=\"text-align: justify;\">Step 2: Copy the code below<\/h3>\n<p style=\"text-align: justify;\">Copy the code below then continue to step 3 to paste the code into the website<\/p>\n<\/div>\n<pre>\/* Code T\u1ef1 \u0111\u1ed9ng l\u01b0u \u1ea3nh v\u00e0o hots *\/\r\n\/* author: https:\/\/how.congdongso.net *\/\r\nclass Auto_Save_Images{\r\nfunction __construct(){ \r\nadd_filter( 'content_save_pre',array($this,'post_save_images') ); }\r\nfunction post_save_images( $content ){\r\nif( ($_POST['save'] || $_POST['publish'] )){\r\nset_time_limit(240);\r\nglobal $post;\r\n$post_id=$post-&gt;ID;\r\n$preg=preg_match_all('\/&lt;img.*?src=\"(.*?)\"\/',stripslashes($content),$matches);\r\nif($preg){\r\nforeach($matches[1] as $image_url){\r\nif(empty($image_url)) continue;\r\n$pos=strpos($image_url,$_SERVER['HTTP_HOST']);\r\nif($pos===false){\r\n$res=$this-&gt;save_images($image_url,$post_id);\r\n$replace=$res['url'];\r\n$content=str_replace($image_url,$replace,$content);}}}}\r\nremove_filter( 'content_save_pre', array( $this, 'post_save_images' ) );\r\nreturn $content;}\r\nfunction save_images($image_url,$post_id){\r\n$file=file_get_contents($image_url);\r\n$post = get_post($post_id);\r\n$posttitle = $post-&gt;post_title;\r\n$postname = sanitize_title($posttitle);\r\n$im_name = \"$postname-$post_id.jpg\";\r\n$res=wp_upload_bits($im_name,'',$file);\r\n$this-&gt;insert_attachment($res['file'],$post_id);\r\nreturn $res;}\r\nfunction insert_attachment($file,$id){\r\n$dirs=wp_upload_dir();\r\n$filetype=wp_check_filetype($file);\r\n$attachment=array(\r\n'guid'=&gt;$dirs['baseurl'].'\/'._wp_relative_upload_path($file),\r\n'post_mime_type'=&gt;$filetype['type'],\r\n'post_title'=&gt;preg_replace('\/.[^.]+$\/','',basename($file)),\r\n'post_content'=&gt;'',\r\n'post_status'=&gt;'inherit'\r\n);\r\n$attach_id=wp_insert_attachment($attachment,$file,$id);\r\n$attach_data=wp_generate_attachment_metadata($attach_id,$file);\r\nwp_update_attachment_metadata($attach_id,$attach_data);\r\nreturn $attach_id;}}\r\nnew Auto_Save_Images();<\/pre>\n<h3 style=\"text-align: justify;\"><!--more-->Step 3: Access the link to paste the code<\/h3>\n<p style=\"text-align: justify;\">After you have logged in and copied the code, follow the link below to paste the code into your website<\/p>\n<p style=\"text-align: justify;\">Go to Interface &gt; Theme file editor &gt; look to the left and find the section <strong>Function.php.\u00a0<\/strong><\/p>\n<figure id=\"attachment_3926\" aria-describedby=\"caption-attachment-3926\" style=\"width: 950px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-3926\" src=\"https:\/\/how.congdongso.net\/wp-content\/uploads\/2023\/02\/auto-copy-file-anh-1.jpg\" alt=\"Code to automatically save images to hot\" width=\"960\" height=\"468\" title=\"\"><figcaption id=\"caption-attachment-3926\" class=\"wp-caption-text\">Link to paste the code<\/figcaption><\/figure>\n<p>Some of your websites may not be found, maybe they are using a child theme or a theme that has not created this section yet, please switch to the parent theme.<\/p>\n<figure id=\"attachment_3927\" aria-describedby=\"caption-attachment-3927\" style=\"width: 476px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-3927\" src=\"https:\/\/how.congdongso.net\/wp-content\/uploads\/2023\/02\/auto-copy-file-anh-1-2.jpg\" alt=\"Code to automatically save images to hot\" width=\"486\" height=\"267\" title=\"\"><figcaption id=\"caption-attachment-3927\" class=\"wp-caption-text\">Convert theme to display Function.php<\/figcaption><\/figure>\n<h3 style=\"text-align: justify;\">Step 4: Check the results<\/h3>\n<p style=\"text-align: justify;\">To check <strong>Code to automatically save images to hot when copying images from other pages<\/strong> Whether it works or not, please do the following:<\/p>\n<p style=\"text-align: justify;\">Create an article with the title of your choice &gt; Copy images and content from another site to this article. At this time, when you check, you still see that the link is from the other party. You proceed to Save the draft of the website and it will automatically reload. Now you just need to check the results again.<\/p>\n<h2 style=\"text-align: justify;\">Summary.<\/h2>\n<p style=\"text-align: justify;\">I recently shared with you the passage <strong>The code automatically saves images to hot when copying images from another page. <\/strong>At the same time, detailed instructions on how to insert and use that code. Hope this article will be really useful to you.<\/p>\n<p style=\"text-align: justify;\">If you find it useful, don&#039;t forget <strong>5* rating<\/strong> and<strong> <a href=\"https:\/\/fb.com\/howto.edu.vn\" target=\"_blank\" rel=\"noopener\">follow Facebook channel<\/a><\/strong> us to be updated with the latest news.<\/p>\n<p style=\"text-align: justify;\">Source: Collector<\/p>","protected":false},"excerpt":{"rendered":"<p>Code t\u1ef1 \u0111\u1ed9ng l\u01b0u \u1ea3nh v\u00e0o hot khi copy h\u00ecnh t\u1eeb trang kh\u00e1c. T\u00ednh n\u0103ng n\u00e0y gi\u00fap t\u1ef1 \u0111\u1ed9ng l\u01b0u c\u00e1c h\u00ecnh \u1ea3nh m\u00e0 b\u1ea1n \u0111\u00e3 sao ch\u00e9p t\u1eeb trang web kh\u00e1c v\u00e0o th\u01b0 m\u1ee5c hot tr\u00ean m\u00e1y t\u00ednh c\u1ee7a b\u1ea1n. Khi b\u1ea1n sao ch\u00e9p m\u1ed9t h\u00ecnh \u1ea3nh t\u1eeb trang web, m\u00e3 s\u1ebd t\u1ef1 \u0111\u1ed9ng &hellip;<\/p>","protected":false},"author":2,"featured_media":11468,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[34],"tags":[176,180],"class_list":["post-3920","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-wordpress","tag-code-hay","tag-code-luu-anh-vao-hot-khi-copy-hinh-tu-trang-khac"],"_links":{"self":[{"href":"https:\/\/how.congdongso.net\/en\/wp-json\/wp\/v2\/posts\/3920","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/how.congdongso.net\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/how.congdongso.net\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/how.congdongso.net\/en\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/how.congdongso.net\/en\/wp-json\/wp\/v2\/comments?post=3920"}],"version-history":[{"count":1,"href":"https:\/\/how.congdongso.net\/en\/wp-json\/wp\/v2\/posts\/3920\/revisions"}],"predecessor-version":[{"id":21055,"href":"https:\/\/how.congdongso.net\/en\/wp-json\/wp\/v2\/posts\/3920\/revisions\/21055"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/how.congdongso.net\/en\/wp-json\/wp\/v2\/media\/11468"}],"wp:attachment":[{"href":"https:\/\/how.congdongso.net\/en\/wp-json\/wp\/v2\/media?parent=3920"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/how.congdongso.net\/en\/wp-json\/wp\/v2\/categories?post=3920"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/how.congdongso.net\/en\/wp-json\/wp\/v2\/tags?post=3920"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}