is_local_attachment()
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.
Uses: url_to_postid()
1 time — 0.001947 sec (very slow) | 50000 times — 80.64 sec (very slow) | PHP 7.0.5, WP 4.4.2
No Hooks.
Return
true|false
. True on success, false on failure.
Usage
is_local_attachment( $url );
- $url(string) (required)
- URL to check
Changelog
Since 2.0.0 | Introduced. |
Code of is_local_attachment() is local attachment WP 6.0
function is_local_attachment( $url ) { if ( strpos( $url, home_url() ) === false ) { return false; } if ( strpos( $url, home_url( '/?attachment_id=' ) ) !== false ) { return true; } $id = url_to_postid( $url ); if ( $id ) { $post = get_post( $id ); if ( 'attachment' === $post->post_type ) { return true; } } return false; }