^ 回到顶部
  • 人生没有定律,每个人都有自己的节奏
  • 本站wordpress建站教程均通过实践后发布,希望对你有帮助
  • 希望你的坚持,都是因为热爱,而不是因为不甘心
  • 8年wordpress建站经验,5星服务品质
  • 那些不愿意让你吃亏的人,才是真正值得你深交的人,也是值得你付出时间的人
  • 阿里云2核2g仅需86元/年

wordpress函数get_custom_logo()用法示例

get_custom_logo( int $blog_id )

Returns a custom logo, linked to home.


描述


参数

$blog_id

(int)
(Optional)
ID of the blog in question. Default is the ID of the current blog.

新用户2核2g仅需86元/年    领取1153套模板    免费cdn流量包    ¥3188礼包


返回值

(string) Custom logo markup.


源代码

File: wp-includes/general-template.php

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

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

	$custom_logo_id = get_theme_mod( 'custom_logo' );

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

		/*
		 * 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' );
		}

		/*
		 * 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.
		 */
		$html = sprintf( '<a href="%1$s" class="custom-logo-link" rel="home" itemprop="url">%2$s</a>',
			esc_url( home_url( '/' ) ),
			wp_get_attachment_image( $custom_logo_id, 'full', false, $custom_logo_attr )
		);
	}

	// If no logo is set but we're in the Customizer, leave a placeholder (needed for the live preview).
	elseif ( is_customize_preview() ) {
		$html = sprintf( '<a href="%1$s" class="custom-logo-link" style="display:none;"><img class="custom-logo"/></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 );
}

更新日志

Version 描述
4.5.0 Introduced.

相关函数

Uses

  • wp-includes/general-template.php:
    get_custom_logo
  • wp-includes/theme.php:
    is_customize_preview()
  • wp-includes/theme.php:
    get_theme_mod()
  • wp-includes/formatting.php:
    esc_url()
  • wp-includes/general-template.php:
    get_bloginfo()
  • wp-includes/load.php:
    is_multisite()
  • wp-includes/load.php:
    get_current_blog_id()
  • wp-includes/link-template.php:
    home_url()
  • wp-includes/plugin.php:
    apply_filters()
  • wp-includes/media.php:
    wp_get_attachment_image()
  • wp-includes/post.php:
    get_post_meta()
  • wp-includes/ms-blogs.php:
    switch_to_blog()
  • wp-includes/ms-blogs.php:
    restore_current_blog()
  • Show 8 more uses


Used By

  • wp-includes/class-wp-customize-manager.php:
    WP_Customize_Manager::_render_custom_logo_partial()
  • wp-includes/general-template.php:
    the_custom_logo()

  1. Skip to note content

    You must log in to vote on the helpfulness of this noteVote results for this note: 1You must log in to vote on the helpfulness of this note

    Contributed by Anthony Hortin

    See Also
    the_custom_logo()
    has_custom_logo()

  2. To get the URL of the custom logo image:

    
    $custom_logo_id = get_theme_mod( 'custom_logo' );
    $image = wp_get_attachment_image_src( $custom_logo_id , 'full' );
    echo $image[0];
    

让小雨知道,这篇文章帮到了你
扫码关注微信公众号zs40086(微搜片)随时随地微信看片,抢先福利电影等你来

热门推荐

如有疑问,请前往问答中心反馈!

反馈