Title: is_local_attachment
Published: April 25, 2014
Last modified: February 24, 2026

---

# is_local_attachment( string $url ): bool

## In this article

 * [Description](https://developer.wordpress.org/reference/functions/is_local_attachment/?output_format=md#description)
 * [Parameters](https://developer.wordpress.org/reference/functions/is_local_attachment/?output_format=md#parameters)
 * [Return](https://developer.wordpress.org/reference/functions/is_local_attachment/?output_format=md#return)
 * [Source](https://developer.wordpress.org/reference/functions/is_local_attachment/?output_format=md#source)
 * [Related](https://developer.wordpress.org/reference/functions/is_local_attachment/?output_format=md#related)
 * [Changelog](https://developer.wordpress.org/reference/functions/is_local_attachment/?output_format=md#changelog)
 * [User Contributed Notes](https://developer.wordpress.org/reference/functions/is_local_attachment/?output_format=md#user-contributed-notes)

[ Back to top](https://developer.wordpress.org/reference/functions/is_local_attachment/?output_format=md#wp--skip-link--target)

Determines whether an attachment URI is local and really an attachment.

## 󠀁[Description](https://developer.wordpress.org/reference/functions/is_local_attachment/?output_format=md#description)󠁿

For more information on this and similar theme functions, check out the [ Conditional Tags](https://developer.wordpress.org/themes/basics/conditional-tags/)
article in the Theme Developer Handbook.

## 󠀁[Parameters](https://developer.wordpress.org/reference/functions/is_local_attachment/?output_format=md#parameters)󠁿

 `$url`stringrequired

URL to check

## 󠀁[Return](https://developer.wordpress.org/reference/functions/is_local_attachment/?output_format=md#return)󠁿

 bool True on success, false on failure.

## 󠀁[Source](https://developer.wordpress.org/reference/functions/is_local_attachment/?output_format=md#source)󠁿

    ```php
    function is_local_attachment( $url ) {
    	if ( ! str_contains( $url, home_url() ) ) {
    		return false;
    	}
    	if ( str_contains( $url, home_url( '/?attachment_id=' ) ) ) {
    		return true;
    	}

    	$id = url_to_postid( $url );
    	if ( $id ) {
    		$post = get_post( $id );
    		if ( 'attachment' === $post->post_type ) {
    			return true;
    		}
    	}
    	return false;
    }
    ```

[View all references](https://developer.wordpress.org/reference/files/wp-includes/post.php/)
[View on Trac](https://core.trac.wordpress.org/browser/tags/6.9.4/src/wp-includes/post.php#L6607)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/6.9.4/src/wp-includes/post.php#L6607-L6623)

## 󠀁[Related](https://developer.wordpress.org/reference/functions/is_local_attachment/?output_format=md#related)󠁿

| Uses | Description | 
| [url_to_postid()](https://developer.wordpress.org/reference/functions/url_to_postid/)`wp-includes/rewrite.php` |

Examines a URL and try to determine the post ID it represents.

  | 
| [home_url()](https://developer.wordpress.org/reference/functions/home_url/)`wp-includes/link-template.php` |

Retrieves the URL for the current site where the front end is accessible.

  | 
| [get_post()](https://developer.wordpress.org/reference/functions/get_post/)`wp-includes/post.php` |

Retrieves post data given a post ID or post object.

  |

[Show 1 more](https://developer.wordpress.org/reference/functions/is_local_attachment/?output_format=md#)
[Show less](https://developer.wordpress.org/reference/functions/is_local_attachment/?output_format=md#)

| Used by | Description | 
| [pingback()](https://developer.wordpress.org/reference/functions/pingback/)`wp-includes/comment.php` |

Pings back the links found in a post.

  |

## 󠀁[Changelog](https://developer.wordpress.org/reference/functions/is_local_attachment/?output_format=md#changelog)󠁿

| Version | Description | 
| [2.0.0](https://developer.wordpress.org/reference/since/2.0.0/) | Introduced. |

## 󠀁[User Contributed Notes](https://developer.wordpress.org/reference/functions/is_local_attachment/?output_format=md#user-contributed-notes)󠁿

 1.  [Skip to note 2 content](https://developer.wordpress.org/reference/functions/is_local_attachment/?output_format=md#comment-content-6646)
 2.   [Himani Panchal](https://profiles.wordpress.org/panchalhimani711/)  [  3 years ago  ](https://developer.wordpress.org/reference/functions/is_local_attachment/#comment-6646)
 3. [You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fis_local_attachment%2F%23comment-6646)
    Vote results for this note: 0[You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fis_local_attachment%2F%23comment-6646)
 4.     ```php
        // Example
        $url = 'https://example.com/uploads/yourimage.jpg';
    
        if ( is_local_attachment( $url ) ) {
            printf(
                esc_html__( '%s is a local attachment.', 'your-text-domain' ),
                esc_url( $url )
            );
        } else {	
            printf(
                esc_html__( '%s is not alocal attachment.', 'your-text-domain' ),
                esc_url( $url )
            );
        }
        ```
    
 5.  [Log in to add feedback](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fis_local_attachment%2F%3Freplytocom%3D6646%23feedback-editor-6646)

You must [log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fis_local_attachment%2F)
before being able to contribute a note or feedback.