Created
June 24, 2019 08:02
-
-
Save johnjullies/bb2f0daef52e9bf4eaed508572591ecf to your computer and use it in GitHub Desktop.
Change Custom Logo URL in Wordpress
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Change the custom logo URL | |
*/ | |
function my_custom_logo_link() { | |
// The logo | |
$custom_logo_id = get_theme_mod( 'custom_logo' ); | |
// If has logo | |
if ( $custom_logo_id ) { | |
// Attr | |
$custom_logo_attr = array( | |
'class' => 'custom-logo', | |
'itemprop' => 'logo', | |
); | |
// Image alt | |
$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' ); | |
} | |
// Get the image | |
$html = sprintf( '<a href="%1$s" class="custom-logo-link" rel="home" itemprop="url">%2$s</a>', | |
esc_url( 'CUSTOM_URL_HERE' ), | |
wp_get_attachment_image( $custom_logo_id, 'full', false, $custom_logo_attr ) | |
); | |
} | |
// Return | |
return $html; | |
} | |
add_filter( 'get_custom_logo', 'my_custom_logo_link' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment