Skip to content

Instantly share code, notes, and snippets.

@kellenmace
Created July 6, 2018 19:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kellenmace/028f0572ba6cbd896e162ca39836832d to your computer and use it in GitHub Desktop.
Save kellenmace/028f0572ba6cbd896e162ca39836832d to your computer and use it in GitHub Desktop.
Check if a remote image file exists in WordPress
<?php
/**
* Check if a remote image file exists.
*
* @param string $url The url to the remote image.
* @return bool Whether the remote image exists.
*/
function km_remote_image_file_exists( $url ) {
$response = wp_remote_head( $url );
return 200 === wp_remote_retrieve_response_code( $response );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment