Last active
October 30, 2017 12:30
-
-
Save chetansatasiya/6c3382c6f5b2b614a414b4073d2933e6 to your computer and use it in GitHub Desktop.
Fetch remote URL image and set to featured image in given postid in WordPress
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function set_featured_image($url,$post_id) { | |
$attachment_id = media_sideload_image( $url, $post_id, '', 'id' ); | |
if ( ! is_wp_error( $attachment_id ) ) { | |
set_post_thumbnail( $post_id, $attachment_id ); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment