# get_custom_logo()

URL: https://chugunov.pro/api-wordpress/functions/get_custom_logo/
Проверено на WordPress 6.9, обновлено 06.08.2026.
Источник: независимый русскоязычный справочник chugunov.pro. Не является официальной документацией WordPress.

Тип: функция.
Появился в версии: 4.5.0.

## Сигнатура

```php
get_custom_logo( int $blog_id ): string
```

## Описание

Возвращает пользовательский логотип со ссылкой на главную страницу, если только тема не поддерживает удаление ссылки на самой главной странице.

## Параметры

- `$blog_id` `int` — необязательный. ID рассматриваемого блога. По умолчанию — ID текущего блога.

## Возвращаемое значение

`string`

## Исходный код

Файл: `wp-includes/general-template.php:1062`

```php
function get_custom_logo( $blog_id = 0 ) {
	$html          = '';
	$switched_blog = false;

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

	// We have a logo. Logo is go.
	if ( has_custom_logo() ) {
		$custom_logo_id   = get_theme_mod( 'custom_logo' );
		$custom_logo_attr = array(
			'class'   => 'custom-logo',
			'loading' => false,
		);

		$unlink_homepage_logo = (bool) get_theme_support( 'custom-logo', 'unlink-homepage-logo' );

		if ( $unlink_homepage_logo && is_front_page() && ! is_paged() ) {
			/*
			 * If on the home page, set the logo alt attribute to an empty string,
			 * as the image is decorative and doesn't need its purpose to be described.
			 */
			$custom_logo_attr['alt'] = '';
		} else {
			/*
			 * If the logo alt attribute is empty, get the site title and explicitly pass it
			 * to the attributes used by wp_get_attachment_image().
			 */
			$image_alt = get_post_meta( $custom_logo_id, '_wp_attachment_image_alt', true );
			if ( empty( $image_alt ) ) {
				$custom_logo_attr['alt'] = get_bloginfo( 'name', 'display' );
			}
		}

		/**
		 * Filters the list of custom logo image attributes.
		 *
		 * @since 5.5.0
		 *
		 * @param array $custom_logo_attr Custom logo image attributes.
		 * @param int   $custom_logo_id   Custom logo attachment ID.
		 * @param int   $blog_id          ID of the blog to get the custom logo for.
		 */
		$custom_logo_attr = apply_filters( 'get_custom_logo_image_attributes', $custom_logo_attr, $custom_logo_id, $blog_id );

		/*
		 * If the alt attribute is not empty, there's no need to explicitly pass it
		 * because wp_get_attachment_image() already adds the alt attribute.
		 */
		$image = wp_get_attachment_image( $custom_logo_id, 'full', false, $custom_logo_attr );

		// Check that we have a proper HTML img element.
		if ( $image ) {

			if ( $unlink_homepage_logo && is_front_page() && ! is_paged() ) {
				// If on the home page, don't link the logo to home.
				$html = sprintf(
					'<span class="custom-logo-link">%1$s</span>',
					$image
				);
			} else {
				$aria_current = ! is_paged() && ( is_front_page() || is_home() && ( (int) get_option( 'page_for_posts' ) !== get_queried_object_id() ) ) ? ' aria-current="page"' : '';

				$html = sprintf(
					'<a href="%1$s" class="custom-logo-link" rel="home"%2$s>%3$s</a>',
					esc_url( home_url( '/' ) ),
					$aria_current,
					$image
				);
			}
		}
	} elseif ( is_customize_preview() ) {
		// If no logo is set but we're in the Customizer, leave a placeholder (needed for the live preview).
		$html = sprintf(
			'<a href="%1$s" class="custom-logo-link" style="display:none;"><img class="custom-logo" alt="" /></a>',
			esc_url( home_url( '/' ) )
		);
	}

	if ( $switched_blog ) {
		restore_current_blog();
	}

	/**
	 * Filters the custom logo output.
	 *
	 * @since 4.5.0
	 * @since 4.6.0 Added the `$blog_id` parameter.
	 *
	 * @param string $html    Custom logo HTML output.
	 * @param int    $blog_id ID of the blog to get the custom logo for.
	 */
	return apply_filters( 'get_custom_logo', $html, $blog_id );
}
```

## История изменений

- 5.5.1 — Disabled lazy-loading by default.
- 5.5.0 — Added option to remove the link on the home page with unlink-homepage-logo theme support for the custom-logo theme feature.
- 4.5.0 — Introduced.

## Связанные

Использует: [`has_custom_logo`](https://chugunov.pro/api-wordpress/functions/has_custom_logo/), [`is_customize_preview`](https://chugunov.pro/api-wordpress/functions/is_customize_preview/), [`get_theme_support`](https://chugunov.pro/api-wordpress/functions/get_theme_support/), [`get_theme_mod`](https://chugunov.pro/api-wordpress/functions/get_theme_mod/), [`is_front_page`](https://chugunov.pro/api-wordpress/functions/is_front_page/), [`is_paged`](https://chugunov.pro/api-wordpress/functions/is_paged/), [`is_home`](https://chugunov.pro/api-wordpress/functions/is_home/), [`get_queried_object_id`](https://chugunov.pro/api-wordpress/functions/get_queried_object_id/), [`wp_get_attachment_image`](https://chugunov.pro/api-wordpress/functions/wp_get_attachment_image/), [`switch_to_blog`](https://chugunov.pro/api-wordpress/functions/switch_to_blog/), [`restore_current_blog`](https://chugunov.pro/api-wordpress/functions/restore_current_blog/), [`esc_url`](https://chugunov.pro/api-wordpress/functions/esc_url/), [`get_bloginfo`](https://chugunov.pro/api-wordpress/functions/get_bloginfo/), [`is_multisite`](https://chugunov.pro/api-wordpress/functions/is_multisite/), [`get_current_blog_id`](https://chugunov.pro/api-wordpress/functions/get_current_blog_id/), [`home_url`](https://chugunov.pro/api-wordpress/functions/home_url/), [`apply_filters`](https://chugunov.pro/api-wordpress/functions/apply_filters/), [`get_option`](https://chugunov.pro/api-wordpress/functions/get_option/), [`get_post_meta`](https://chugunov.pro/api-wordpress/functions/get_post_meta/).
Используется в: `WP_Customize_Manager::_render_custom_logo_partial`, [`the_custom_logo`](https://chugunov.pro/api-wordpress/functions/the_custom_logo/).

Оригинал в официальной документации: https://developer.wordpress.org/reference/functions/get_custom_logo/
