wp_insert_attachment( string|array $args, string $file = false, int $parent, bool $wp_error = false )

Insert an attachment.

25 related functions found for: wp_insert_attachment

Top ↑

Related terms found for this post

wp-parser-related-wordsattach, attachment, attachments, insert, post-php, post-typ, post-type, wp-includes, wp-insert
wp-parser-packagePost, WordPress

Top ↑

Terms Used Terms Used

Terms used in the related posts query

  • attach
  • attachment
  • attachments
  • insert
  • Post
  • post-php
  • post-typ
  • post-type
  • wp-includes
  • wp-includes/post.php
  • wp-insert
  • post

Top ↑

Description Description

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.

Top ↑

Parameters Parameters


(string|array) (Required) Arguments for inserting an attachment.


(string) (Optional) Filename.

Default value: false


(int) (Optional) Parent post ID.


(bool) (Optional) Whether to return a WP_Error on failure.

Default value: false

Top ↑

Return Return

(int|WP_Error) The attachment ID on success. The value 0 or WP_Error on failure.

Top ↑

Source Source

File: wp-includes/post.php


Top ↑

Changelog Changelog

Version Description
4.7.0 Added the $wp_error parameter to allow a WP_Error to be returned on failure.
2.0.0 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

You must log in before being able to contribute a note or feedback.