Skip to content

Commit

Permalink
TwentyTen site logo support
Browse files Browse the repository at this point in the history
  • Loading branch information
bschneidewind committed Feb 13, 2025
1 parent 108af60 commit d9bdeca
Show file tree
Hide file tree
Showing 3 changed files with 110 additions and 10 deletions.
96 changes: 94 additions & 2 deletions src/wp-content/themes/twentyten/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,17 @@ function twentyten_setup() {
// Add default posts and comments RSS feed links to head.
add_theme_support( 'automatic-feed-links' );

// Enable support for custom logo.
add_theme_support(
'custom-logo',
array(
'height' => 100,
'width' => 300,
'flex-height' => true,
'flex-width' => true,
)
);

/*
* Make theme available for translation.
* Translations can be filed in the /languages/ directory.
Expand Down Expand Up @@ -181,8 +192,6 @@ function twentyten_setup() {
'height' => apply_filters( 'twentyten_header_image_height', 198 ),
// Support flexible heights.
'flex-height' => true,
// Don't support text inside the header image.
'header-text' => false,
// Callback for styling the header preview in the admin.
'admin-head-callback' => 'twentyten_admin_header_style',
);
Expand Down Expand Up @@ -809,3 +818,86 @@ function wp_body_open() {
do_action( 'wp_body_open' );
}
endif;

/**
* Displays the site logo, either text or image.
*
* @param array $args Arguments for displaying the site logo either as an image or text.
* @param bool $display Display or return the HTML.
* @return string Compiled HTML based on our arguments.
*/
function twentyten_site_logo( $args = array() ) {
$site_title = get_bloginfo( 'name' );
$contents = '';

$defaults = array(
'logo' => '%1$s',
'home_title' => '<h1><a href="%1$s" aria-current="page" rel="home">%2$s</a></h1>',
'single_title' => '<a href="%1$s" rel="home">%2$s</a>',
'condition' => ( is_front_page() || is_home() && ( (int) get_option( 'page_for_posts' ) !== get_queried_object_id() ) ) && ! is_paged(),
);

$args = wp_parse_args( $args, $defaults );

/**
* Filters the arguments for `twentyten_site_logo()`.
*
* @param array $args Parsed arguments.
* @param array $defaults Function's default arguments.
*/
$args = apply_filters( 'twentyten_site_logo_args', $args, $defaults );

if ( has_custom_logo() ) {
$contents = get_custom_logo();
if ( ! display_header_text() ) {
$contents .= '<span class="screen-reader-text">' . esc_html( $site_title ) . '</span>';
}
}
if ( ! has_custom_logo() || display_header_text() ) {
$wrap = $args['condition'] ? 'home_title' : 'single_title';
$contents .= sprintf( $args[ $wrap ], esc_url( get_home_url( null, '/' ) ), esc_html( $site_title ) );
}

$html = '<div id="site-title">' . $contents . '</div>';

/**
* Filters the arguments for `twentyten_site_logo()`.
*
* @param string $html Compiled html based on our arguments.
* @param array $args Parsed arguments.
* @param string $contents HTML for site title or logo.
*/
$html = apply_filters( 'twentyten_site_logo', $html, $args, $contents );

echo $html; //phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
}

/**
* Implements Twenty Ten theme options into Customizer
*
* @param WP_Customize_Manager $wp_customize Customizer object.
*/
function twentyten_customize_register( $wp_customize ) {
if ( isset( $wp_customize->selective_refresh ) ) {
$wp_customize->selective_refresh->add_partial(
'custom_logo',
array(
'selector' => '#site-title',
'render_callback' => 'twentyten_customize_partial_site_logo',
'container_inclusive' => true,
)
);
}
}
add_action( 'customize_register', 'twentyten_customize_register' );

if ( ! function_exists( 'twentyten_customize_partial_site_logo' ) ) {
/**
* Render the site logo for the selective refresh partial.
*
* Doing it this way so we don't have issues with `render_callback`'s arguments.
*/
function twentyten_customize_partial_site_logo() {
twentyten_site_logo();
}
}
11 changes: 4 additions & 7 deletions src/wp-content/themes/twentyten/header.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,10 @@
<div id="header">
<div id="masthead">
<div id="branding" role="banner">
<?php $heading_tag = ( is_home() || is_front_page() ) ? 'h1' : 'div'; ?>
<<?php echo $heading_tag; ?> id="site-title">
<span>
<a href="<?php echo esc_url( home_url( '/' ) ); ?>" rel="home"><?php bloginfo( 'name' ); ?></a>
</span>
</<?php echo $heading_tag; ?>>
<div id="site-description"><?php bloginfo( 'description' ); ?></div>
<?php twentyten_site_logo(); ?>
<?php if ( get_bloginfo( 'description' ) ) : ?>
<div id="site-description"><?php bloginfo( 'description' ); ?></div>
<?php endif; ?>

<?php
// Compatibility with versions of WordPress prior to 3.4.
Expand Down
13 changes: 12 additions & 1 deletion src/wp-content/themes/twentyten/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,8 @@ a:hover {
padding: 30px 0 0 0;
}
#site-title {
align-items: center;
display: flex;
float: left;
font-size: 30px;
line-height: 36px;
Expand All @@ -367,6 +369,10 @@ a:hover {
font-weight: bold;
text-decoration: none;
}
#site-title h1 {
font-size: 30px;
line-height: 36px;
}
#site-description {
clear: right;
float: right;
Expand All @@ -375,14 +381,19 @@ a:hover {
width: 220px;
}

.custom-logo-link {
margin-right: 16px;
}
/* This is the custom header image */
#branding img {
border-top: 4px solid #000;
border-bottom: 1px solid #000;
display: block;
float: left;
}

#branding img.custom-logo {
border: none;
}

/* =Menu
-------------------------------------------------------------- */
Expand Down

0 comments on commit d9bdeca

Please sign in to comment.