Skip to content

Instantly share code, notes, and snippets.

Forked from smutek/brand.php
Created Jan 20, 2018
What would you like to do?
Filter WordPress Custom Logo
* Site Brand
* Output site branding
* Use native WordPress site logo with custom (bootstrap friendly) markup
* Falls back to text title if logo is not set.
* @param $html
* @return string
function siteBrand($html)
// grab the site name as set in customizer options
$site = get_bloginfo('name');
// Wrap the site name in an H1 if on home, in a paragraph tag if not.
is_front_page() ? $title = '<h1>' . $site . '</h1>' : $title = '<p>' . $site . '</p>';
// Grab the home URL
$home = esc_url(home_url('/'));
// Class for the link
$class = 'navbar-brand';
// Set anchor content to $title
$content = $title;
// Check if there is a custom logo set in customizer options...
if (has_custom_logo()) {
// get the URL to the logo
$logo = wp_get_attachment_image(get_theme_mod('custom_logo'), 'full', false, array(
'class' => 'brand-logo img-responsive',
'itemprop' => 'logo',
// we have a logo, so let's update the $content variable
$content = $logo;
// include the site name markup, hidden with screen reader friendly styles
$content .= '<span class="sr-only">' . $title . '</span>';
// construct the final html
$html = sprintf('<a href="%1$s" class="%2$s" rel="home" itemprop="url">%3$s</a>', $home, $class, $content);
// return the result to the front end
return $html;
add_filter('get_custom_logo', __NAMESPACE__ . '\\siteBrand');
<header class="banner navbar navbar-inverse navbar-static-top" role="banner">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target=".navbar-collapse">
<span class="sr-only"><?= __('Toggle navigation', 'sage'); ?></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<?php the_custom_logo(); ?>
<nav class="collapse navbar-collapse" role="navigation">
if (has_nav_menu('primary_navigation')) :
wp_nav_menu(['theme_location' => 'primary_navigation', 'menu_class' => 'nav navbar-nav']);
// Enable custom logo support
add_theme_support( 'custom-logo' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment