Skip to content

Instantly share code, notes, and snippets.

@hawkidoki
Created May 24, 2018 14:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hawkidoki/2dc84c7940cce05e9febd5344cb7ffdf to your computer and use it in GitHub Desktop.
Save hawkidoki/2dc84c7940cce05e9febd5344cb7ffdf to your computer and use it in GitHub Desktop.
<?php
/**
* The Logo
*/
function hwk_the_logo(){
echo hwk_get_logo();
}
/**
* Get The Logo
*/
function hwk_get_logo(){
if(!has_custom_logo())
return '<a href="' . esc_url(home_url('/')) . '" class="custom-logo-link" rel="home" itemprop="url"><img src="' . hwk_get_logo_url() . '" alt="' . hwk_get_logo_alt() . '" /></a>';
return get_custom_logo();
}
/**
* Filter Logo HTML
*/
add_filter('get_custom_logo', 'hwk_logo_filter_html');
function hwk_logo_filter_html($html){
return str_replace('itemprop="url"', 'itemprop="url" id="logo"', $html);
}
/**
* Logo URL
*/
function hwk_the_logo_url(){
echo hwk_get_logo_url();
}
/**
* Get Logo URL
*/
function hwk_get_logo_url(){
if(!has_custom_logo())
return '';
$logo = wp_get_attachment_image_src(get_theme_mod('custom_logo'), 'full');
return $logo[0];
}
/**
* Logo ALT
*/
function hwk_the_logo_alt(){
echo hwk_get_logo_alt();
}
/**
* Get Logo ALT
*/
function hwk_get_logo_alt(){
if(!has_custom_logo())
return get_bloginfo('name', 'display');
$logo_id = get_theme_mod('custom_logo');
$alt = get_post_meta($logo_id, '_wp_attachment_image_alt', true);
if(empty($alt))
return get_bloginfo('name', 'display');
return $alt;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment