get_site_icon_url

函式
get_site_icon_url ( $size = 512, $url = '', $blog_id = 0 )
引數
  • (int) $size Optional. Size of the site icon. Default 512 (pixels).
    Required:
    Default: 512
  • (string) $url Optional. Fallback url if no site icon is found. Default empty.
    Required:
    Default: (empty)
  • (int) $blog_id Optional. ID of the blog to get the site icon for. Default current blog.
    Required:
返回值
  • (string) Site Icon URL.
定義位置
相關方法
site_icon_urlget_site_urlget_sitemap_urlget_site_optionatom_site_icon
引入
4.3.0
棄用
-

get_site_icon_url: 這個函式檢索網站圖示的URL。它接受一個引數:網站的ID。它以字串形式返回圖示的URL。

返回網站圖示的URL。

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
function get_site_icon_url( $size = 512, $url = '', $blog_id = 0 ) {
$switched_blog = false;
if ( is_multisite() && ! empty( $blog_id ) && get_current_blog_id() !== (int) $blog_id ) {
switch_to_blog( $blog_id );
$switched_blog = true;
}
$site_icon_id = get_option( 'site_icon' );
if ( $site_icon_id ) {
if ( $size >= 512 ) {
$size_data = 'full';
} else {
$size_data = array( $size, $size );
}
$url = wp_get_attachment_image_url( $site_icon_id, $size_data );
}
if ( $switched_blog ) {
restore_current_blog();
}
/**
* Filters the site icon URL.
*
* @since 4.4.0
*
* @param string $url Site icon URL.
* @param int $size Size of the site icon.
* @param int $blog_id ID of the blog to get the site icon for.
*/
return apply_filters( 'get_site_icon_url', $url, $size, $blog_id );
}
function get_site_icon_url( $size = 512, $url = '', $blog_id = 0 ) { $switched_blog = false; if ( is_multisite() && ! empty( $blog_id ) && get_current_blog_id() !== (int) $blog_id ) { switch_to_blog( $blog_id ); $switched_blog = true; } $site_icon_id = get_option( 'site_icon' ); if ( $site_icon_id ) { if ( $size >= 512 ) { $size_data = 'full'; } else { $size_data = array( $size, $size ); } $url = wp_get_attachment_image_url( $site_icon_id, $size_data ); } if ( $switched_blog ) { restore_current_blog(); } /** * Filters the site icon URL. * * @since 4.4.0 * * @param string $url Site icon URL. * @param int $size Size of the site icon. * @param int $blog_id ID of the blog to get the site icon for. */ return apply_filters( 'get_site_icon_url', $url, $size, $blog_id ); }
function get_site_icon_url( $size = 512, $url = '', $blog_id = 0 ) {
	$switched_blog = false;

	if ( is_multisite() && ! empty( $blog_id ) && get_current_blog_id() !== (int) $blog_id ) {
		switch_to_blog( $blog_id );
		$switched_blog = true;
	}

	$site_icon_id = get_option( 'site_icon' );

	if ( $site_icon_id ) {
		if ( $size >= 512 ) {
			$size_data = 'full';
		} else {
			$size_data = array( $size, $size );
		}
		$url = wp_get_attachment_image_url( $site_icon_id, $size_data );
	}

	if ( $switched_blog ) {
		restore_current_blog();
	}

	/**
	 * Filters the site icon URL.
	 *
	 * @since 4.4.0
	 *
	 * @param string $url     Site icon URL.
	 * @param int    $size    Size of the site icon.
	 * @param int    $blog_id ID of the blog to get the site icon for.
	 */
	return apply_filters( 'get_site_icon_url', $url, $size, $blog_id );
}

常見問題

FAQs
檢視更多 >