WordPress at a glance

is_local_attachment() WP 1.0

Check if the attachment URI is local one and is really an attachment.

For more information on this and similar theme functions, check out the Conditional Tags article in the Theme Developer Handbook.

Works based on: url_to_postid()
✈ 1 time = 0.001947s = very slow | 50000 times = 80.64s = very slow | PHP 7.0.5, WP 4.4.2

No Hooks.


true/false. True on success, false on failure.


is_local_attachment( $url );
$url(string) (required)
URL to check

Code of is local attachment: wp-includes/post.php VER 5.0.3

function is_local_attachment($url) {
	if (strpos($url, home_url()) === false)
		return false;
	if (strpos($url, home_url('/?attachment_id=')) !== false)
		return true;
	if ( $id = url_to_postid($url) ) {
		$post = get_post($id);
		if ( 'attachment' == $post->post_type )
			return true;
	return false;

Related Functions

From tag: Conditional tags (all)

More from category: Attachments (Media files)

No comments
    Hello, !     Log In . Register