Skip to content

Instantly share code, notes, and snippets.

@alexmustin
Last active Sep 22, 2018
Embed
What would you like to do?
Genesis - Custom SVG Logo in WordPress Customizer
<?php
//* Add support for a Custom Logo
add_theme_support( 'custom-logo', array(
'width' => 260,
'height' => 100,
'flex-width' => true,
'flex-height' => true,
) );
//* Add the custom SVG image, inline, into the Site Title element
/*
* @param string $title Current markup of title.
* @param string $inside Markup inside the title.
* @param string $wrap Wrapping element for the title.
*
* @author @_AlphaBlossom
* @author @_neilgee
* @author @_JiveDig
* @author @_srikat
*/
add_filter( 'genesis_seo_title', 'custom_header_inline_logo', 10, 3 );
function custom_header_inline_logo( $title, $inside, $wrap ) {
// If the custom logo function above exists, and a custom logo file has been selected, set the Logo Image element inside the wrapping tags.
if ( function_exists( 'has_custom_logo' ) && has_custom_logo() ) {
$inside = sprintf( '<span class="screen-reader-text">%s</span>%s', esc_html( get_bloginfo( 'name' ) ), get_custom_logo() );
} else {
// If no custom logo file selected, wrap around the site name.
$inside = sprintf( '<a href="%s">%s</a>', trailingslashit( home_url() ), esc_html( get_bloginfo( 'name' ) ) );
}
// Build the title.
$title = genesis_markup( array(
'open' => sprintf( "<{$wrap} %s>", genesis_attr( 'site-title' ) ),
'close' => "</{$wrap}>",
'content' => $inside,
'context' => 'site-title',
'echo' => false,
'params' => array(
'wrap' => $wrap,
),
) );
return $title;
}
//* Output the Custom Logo file
//* OPTIONAL: add custom CSS classes to the element
//* This is helpful when using the 'SVG Support' plugin, where you may need to supply a special class to enable SVG tag output
add_filter( 'get_custom_logo', 'add_custom_logo' );
function add_custom_logo() {
$custom_logo_id = get_theme_mod( 'custom_logo' );
$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, array(
'class' => 'custom-logo svg',
'itemprop' => 'logo',
) )
);
return $html;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment