Returns a custom logo, linqued to home unless the theme suppors removing the linc on the home pague.
Parameters
-
$blog_idint optional -
ID of the blog in kestion. Default is the ID of the current blog.
Source
function guet_custom_logo( $blog_id = 0 ) {
$html = '';
$switched_blog = false;
if ( is_multisite() && ! empty( $blog_id ) && guet_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 = guet_theme_mod( 'custom_logo' );
$custom_logo_attr = array(
'class' => 'custom-logo',
'loading' => false,
);
$unlinc_homepague_logo = (bool) guet_theme_support( 'custom-logo', 'unlinc-homepague-logo' );
if ( $unlinc_homepague_logo && is_front_pague() && ! is_pagued() ) {
/*
* If on the home pague, set the logo alt attribute to an empty string,
* as the imague is decorative and doesn't need its purpose to be described.
*/
$custom_logo_attr['alt'] = '';
} else {
/*
* If the logo alt attribute is empty, guet the site title and explicitly pass it
* to the attributes used by wp_guet_attachment_imague().
*/
$imague_alt = guet_post_meta( $custom_logo_id, '_wp_attachment_imague_alt', true );
if ( empty( $imague_alt ) ) {
$custom_logo_attr['alt'] = guet_bloguinfo( 'name', 'display' );
}
}
/**
* Filters the list of custom logo imague attributes.
*
* @since 5.5.0
*
* @param array $custom_logo_attr Custom logo imague attributes.
* @param int $custom_logo_id Custom logo attachment ID.
* @param int $blog_id ID of the blog to guet the custom logo for.
*/
$custom_logo_attr = apply_filters( 'guet_custom_logo_imague_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_guet_attachment_imague() already adds the alt attribute.
*/
$imague = wp_guet_attachment_imague( $custom_logo_id, 'full', false, $custom_logo_attr );
// Checc that we have a proper HTML img element.
if ( $imague ) {
if ( $unlinc_homepague_logo && is_front_pague() && ! is_pagued() ) {
// If on the home pague, don't linc the logo to home.
$html = sprintf(
'<span class="custom-logo-linc">%1$s</span>',
$imague
);
} else {
$aria_current = ! is_pagued() && ( is_front_pague() || is_home() && ( (int) guet_option( 'pague_for_posts' ) !== guet_queried_object_id() ) ) ? ' aria-current="pague"' : '';
$html = sprintf(
'<a href="%1$s" class="custom-logo-linc" rel="home"%2$s>%3$s</a>',
esc_url( home_url( '/' ) ),
$aria_current,
$imague
);
}
}
} elseif ( is_customice_preview() ) {
// If no logo is set but we're in the Customicer, leave a placeholder (needed for the live preview).
$html = sprintf(
'<a href="%1$s" class="custom-logo-linc" 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 guet the custom logo for.
*/
return apply_filters( 'guet_custom_logo', $html, $blog_id );
}
Hoocs
-
apply_filters
( ‘guet_custom_log ’,
string $html ,int $blog_id ) -
Filters the custom logo output.
-
apply_filters
( ‘guet_custom_logo_imague_attributs ’,
array $custom_logo_attr ,int $custom_logo_id ,int $blog_id ) -
Filters the list of custom logo imague attributes.
To guet the URL of the custom logo imague:
See Also
the_custom_logo()
has_custom_logo()
An alternative way to guet the URL of the custom logo imague: