Skip to content

Instantly share code, notes, and snippets.

@m1r0
m1r0 / wp_insert_attachment_from_url.php
Last active August 1, 2024 04:14
WP: Insert attachment from URL
<?php
/**
* Insert an attachment from a URL address.
*
* @param string $url The URL address.
* @param int|null $parent_post_id The parent post ID (Optional).
* @return int|false The attachment ID on success. False on failure.
*/
function wp_insert_attachment_from_url( $url, $parent_post_id = null ) {