get_custom_logo

Returns a custom logo, linked to home.

Description

(string) get_custom_logo( (int) $blog_id = 0 ); 

Returns (string)

Custom logo markup.

Parameters (1)

0. $blog_id — Optional. (int)
ID of the blog in question. Default is the ID of the current blog.

Usage

  1. if ( !function_exists( 'get_custom_logo' ) ) { 
  2. require_once ABSPATH . WPINC . '/general-template.php'; 
  3.  
  4. // Optional. ID of the blog in question. Default is the ID of the current blog. 
  5. $blog_id = -1; 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = get_custom_logo($blog_id); 
  9.  

Defined (1)

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

/wp-includes/general-template.php  
  1. function get_custom_logo( $blog_id = 0 ) { 
  2. $html = ''; 
  3. $switched_blog = false; 
  4.  
  5. if ( is_multisite() && ! empty( $blog_id ) && (int) $blog_id !== get_current_blog_id() ) { 
  6. switch_to_blog( $blog_id ); 
  7. $switched_blog = true; 
  8.  
  9. $custom_logo_id = get_theme_mod( 'custom_logo' ); 
  10.  
  11. // We have a logo. Logo is go. 
  12. if ( $custom_logo_id ) { 
  13. $html = sprintf( '<a href="%1$s" class="custom-logo-link" rel="home" itemprop="url">%2$s</a>',  
  14. esc_url( home_url( '/' ) ),  
  15. wp_get_attachment_image( $custom_logo_id, 'full', false, array( 
  16. 'class' => 'custom-logo',  
  17. 'itemprop' => 'logo',  
  18. ) ) 
  19. ); 
  20.  
  21. // If no logo is set but we're in the Customizer, leave a placeholder (needed for the live preview). 
  22. elseif ( is_customize_preview() ) { 
  23. $html = sprintf( '<a href="%1$s" class="custom-logo-link" style="display:none;"><img class="custom-logo"/></a>',  
  24. esc_url( home_url( '/' ) ) 
  25. ); 
  26.  
  27. if ( $switched_blog ) { 
  28.  
  29. /** 
  30. * Filters the custom logo output. 
  31. * @since 4.5.0 
  32. * @since 4.6.0 Added the `$blog_id` parameter. 
  33. * @param string $html Custom logo HTML output. 
  34. * @param int $blog_id ID of the blog to get the custom logo for. 
  35. */ 
  36. return apply_filters( 'get_custom_logo', $html, $blog_id );