is_local_attachment()
Проверено на WordPress 6.9, обновлено Источник: WordPress Developer Resources.
Сигнатура
is_local_attachment( string $url ): bool
Описание
Дополнительные сведения об этой и похожих функциях темы см. в статье о Conditional Tags в Theme Developer Handbook.
Оригинал (английский)
For more information on this and similar theme functions, check out the Conditional Tags article in the Theme Developer Handbook.
Параметры
$url
string
обязательный
Возвращаемое значение
bool
Исходный код
wp-includes/post.php:6606
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;
}
История изменений
| Версия | Описание |
|---|---|
| 2.0.0 | Introduced. |

