我正在尝试使用 WordPress 的新自定义徽标功能来完成以下任务:
- 显示默认/备用徽标。
- 如果 WordPress 版本支持自定义徽标,则允许用户在定制器中将默认/备用徽标替换为自定义徽标。
- 如果 WordPress 版本不支持自定义徽标或未设置自定义徽标(或已删除),则显示默认/备用徽标。
到目前为止,这是我必须使用的最佳代码:
<?php if ( function_exists( 'the_custom_logo' ) ) : ?>
<?php if ( has_custom_logo() ) : ?>
<?php the_custom_logo(); ?>
<?php else : ?>
<h1 class="site-title"><a href="<?php echo esc_url( home_url( '/' ) ); ?>" rel="home" title="<?php bloginfo( 'name' ); ?>"><img src="<?php echo get_stylesheet_directory_uri(); ?>/images/logo.png" alt="<?php bloginfo( 'name' ); ?>" width="100" height="50" /></a></h1>
<?php endif; ?>
<?php else : ?>
<h1 class="site-title"><a href="<?php echo esc_url( home_url( '/' ) ); ?>" rel="home" title="<?php bloginfo( 'name' ); ?>"><img src="<?php echo get_stylesheet_directory_uri(); ?>/images/logo.png" alt="<?php bloginfo( 'name' ); ?>" width="100" height="50" /></a></h1>
<?php endif; ?>
是否有一种更清洁或更有效的方法来执行此操作,而无需重复两次后备图像的代码?