If you set the 'ID' in the $args parameter, it will mean that you are updating and attempt to update the attachment. You can also set the attachment name or title by setting the key 'post_name' or 'post_title'. You can set the dates for the attachment manually by setting the 'post_date' and 'post_date_gmt' keys' values. By default, the comments will use the default settings for whether the comments are allowed. You can close them manually or keep them open by setting the value for the 'comment_status' key.
Parameters
$argsstring|array
Arguments for inserting an attachment.
$filestring|falseoptional
Filename. Default false.Default: false
$parent_post_idintoptional
Parent post ID or 0 for no parent. Default 0.Default: 0
$wp_errorbooloptional
Whether to return a WP_Error on failure. Default false.Default: false
$fire_after_hooksbooloptional
Whether to fire the after insert hooks. Default true.Default: true
Return
int|WP_Error
The attachment ID on success. The value 0 or WP_Error on failure.
Uses · 2
wp_parse_args()Merges user defined arguments into defaults array.
Signature, return type and hooks compared across 5 parsed releases.
5.6.0
Added the $fire_after_hooks parameter.from the docblock
4.7.0
Added the $wp_error parameter to allow a WP_Error to be returned on failure.from the docblock
2.0.0
Introduced.from the docblock
About this page
Parsed data
Generated from the wordpress-develop 6.7.7 tag, from src/wp-includes/post.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it.
Corrections
Something wrong on this page? Report it and it gets fixed in the next regeneration.