WP_Site_Icon::insert_attachment() WordPress Method

The WP_Site_Icon::insert_attachment() method is used to insert an attachment into a WordPress site. This is typically used to add an icon to a WordPress site.

WP_Site_Icon::insert_attachment( array $attachment, string $file ) #

Inserts an attachment.


Parameters

$attachment

(array)(Required)An array with attachment object data.

$file

(string)(Required)File path of the attached image.


Top ↑

Return

(int) Attachment ID.


Top ↑

Source

File: wp-admin/includes/class-wp-site-icon.php

	public function insert_attachment( $attachment, $file ) {
		$attachment_id = wp_insert_attachment( $attachment, $file );
		$metadata      = wp_generate_attachment_metadata( $attachment_id, $file );

		/**
		 * Filters the site icon attachment metadata.
		 *
		 * @since 4.3.0
		 *
		 * @see wp_generate_attachment_metadata()
		 *
		 * @param array $metadata Attachment metadata.
		 */
		$metadata = apply_filters( 'site_icon_attachment_metadata', $metadata );
		wp_update_attachment_metadata( $attachment_id, $metadata );

		return $attachment_id;
	}


Top ↑

Changelog

Changelog
VersionDescription
4.3.0Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.