get_site_icon_url

Returns the Site Icon URL.

Description

(string) get_site_icon_url( (int) $size = 512, (string) $url = '', (int) $blog_id = 0 ); 

Returns (string)

Site Icon URL.

Parameters (3)

0. $size — Optional. (int) => 512
Size of the site icon. Default 512 (pixels).
1. $url — Optional. (string) => ''
Fallback url if no site icon is found. Default empty.
2. $blog_id — Optional. (int)
ID of the blog to get the site icon for. Default current blog.

Usage

  1. if ( !function_exists( 'get_site_icon_url' ) ) { 
  2. require_once ABSPATH . WPINC . '/general-template.php'; 
  3.  
  4. // Optional. Size of the site icon. Default 512 (pixels). 
  5. $size = 512; 
  6.  
  7. // Optional. Fallback url if no site icon is found. Default empty. 
  8. $url = ''; 
  9.  
  10. // Optional. ID of the blog to get the site icon for. Default current blog. 
  11. $blog_id = -1; 
  12.  
  13. // NOTICE! Understand what this does before running. 
  14. $result = get_site_icon_url($size, $url, $blog_id); 
  15.  

Defined (1)

The function is defined in the following location(s).

/wp-includes/general-template.php  
  1. function get_site_icon_url( $size = 512, $url = '', $blog_id = 0 ) { 
  2. $switched_blog = false; 
  3.  
  4. if ( is_multisite() && ! empty( $blog_id ) && (int) $blog_id !== get_current_blog_id() ) { 
  5. switch_to_blog( $blog_id ); 
  6. $switched_blog = true; 
  7.  
  8. $site_icon_id = get_option( 'site_icon' ); 
  9.  
  10. if ( $site_icon_id ) { 
  11. if ( $size >= 512 ) { 
  12. $size_data = 'full'; 
  13. } else { 
  14. $size_data = array( $size, $size ); 
  15. $url = wp_get_attachment_image_url( $site_icon_id, $size_data ); 
  16.  
  17. if ( $switched_blog ) { 
  18.  
  19. /** 
  20. * Filters the site icon URL. 
  21. * @site 4.4.0 
  22. * @param string $url Site icon URL. 
  23. * @param int $size Size of the site icon. 
  24. * @param int $blog_id ID of the blog to get the site icon for. 
  25. */ 
  26. return apply_filters( 'get_site_icon_url', $url, $size, $blog_id );