可以使用the_custom_logo()函数在主题中显示自定义徽标。
如何判断是否上载logo:
<?php if ( has_custom_logo() ) : ?>
<div class="site-logo"><?php the_custom_logo(); ?></div>
<?php endif; ?>
通常,徽标会添加到header.php主题文件中,但也可以在其他位置。
自定义徽标模板标签
考虑兼容性
包装在一个function_exists()调用中,以保持与旧版本WordPress的向后兼容性,如下所示:
if ( function_exists( 'the_custom_logo' ) ) {
the_custom_logo();
}
相关函数
要管理在前端显示自定义Logo,可以使用以下三个模板标签:
- get_custom_logo() – 返回自定义Logo的标记。
- the_custom_logo() – 显示自定义Logo的标记。
- has_custom_logo() – 返回一个布尔值true/false,是否设置了自定义徽标。