Nếu bạn thường xuyên post bài bằng wordpress sẽ thấy việc download hình ảnh từ trang web nào đó, rồi upload lên wordpress, chèn vào bài viết tốn kém thời gian đến mức nào.

Tại sao không lấy luôn hình ảnh từ website khác chèn vào web mình?
- Vì như vậy hình ảnh sẽ phụ thuộc vào host của người khác, nếu host của họ có vấn đề, hình ảnh trên web của bạn cũng “tèo” luôn
- Ảnh hưởng SEO, cái này nếu bạn quan tâm về SEO hình ảnh sẽ thấy vô tình đã cho người khác 1 backlink
Vậy để giảm bớt công đoạn thì làm cách nào, đơn giản copy đoạn code này vào function.php của theme và thử copy 1 ảnh của web khác và publish bài viết thôi, việc còn lại để wordpress lo.
Mình không khuyến khích các bạn sử dụng plugin vì có thể dẫn đến chậm website, cái nào chèn code được thì mình chèn nhé.
class Auto_Save_Images{ function __construct(){ add_filter( ‘content_save_pre’,array($this,’post_save_images’) ); } function post_save_images( $content ){ if( ($_POST[‘save’] || $_POST[‘publish’] )){ set_time_limit(240); global $post; $post_id=$post->ID; $preg=preg_match_all(‘/<img.*?src=”(.*?)”/’,stripslashes($content),$matches); if($preg){ foreach($matches[1] as $image_url){ if(empty($image_url)) continue; $pos=strpos($image_url,$_SERVER[‘HTTP_HOST’]); if($pos===false){ $res=$this->save_images($image_url,$post_id); $replace=$res[‘url’]; $content=str_replace($image_url,$replace,$content); } } } } remove_filter( ‘content_save_pre’, array( $this, ‘post_save_images’ ) ); return $content; } function save_images($image_url,$post_id){ $file=file_get_contents($image_url); $post = get_post($post_id); $posttitle = $post->post_title; $postname = sanitize_title($posttitle); $im_name = “$postname-$post_id.jpg”; $res=wp_upload_bits($im_name,”,$file); $this->insert_attachment($res[‘file’],$post_id); return $res; } function insert_attachment($file,$id){ $dirs=wp_upload_dir(); $filetype=wp_check_filetype($file); $attachment=array(‘guid’=>$dirs[‘baseurl’].’/’._wp_relative_upload_path($file),’post_mime_type’=>$filetype[‘type’],’post_title’=>preg_replace(‘/.[^.]+$/’,”,basename($file)),’post_content’=>”,’post_status’=>’inherit’ ); $attach_id=wp_insert_attachment($attachment,$file,$id); $attach_data=wp_generate_attachment_metadata($attach_id,$file); wp_update_attachment_metadata($attach_id,$attach_data); return $attach_id; } } new Auto_Save_Images(); add_filter(‘use_block_editor_for_post’, ‘__return_false’);
Sản Phẩm Vừa Mới Cập Nhật
- [VShare Preset] Bộ Sưu Tập 109 Tone Màu Nhật Bản Từ Taobao (XMP/CUBE)
- 10 lời khuyên giúp bạn nâng “trình” nhiếp ảnh
- [VShare Preset] Bộ Preset Tone Màu Lạnh Cho Ảnh Mùa Đông Mới Nhất 2022 (XMP)
- [Share preset PC + Mobile] 3 Premium Lightroom Presets Trị Giá 30$ của NAG Sandra đến từ Crotia (Update 2025)
- [Share LUTs] 179 Luts Màu Chọn Lọc Đặt Mua Tại Taobao (Cube)











![[Full Combo] 68 Preset Màu Film Từ NAG Sơn Tiêu Ánh Họa - Đỉnh Cao Giả Lập Màu Film (XMP/CUBE/ICC)](https://shopthietke.com/wp-content/uploads/2026/03/shopthietke-com-Shopthietke.com_-394.webp)



















