WordPress 4.5 - built in theme logo support

wordpress
#1

add_theme_support( 'site-logo', size );
add_theme_support( 'custom-logo' );

details: https://codex.wordpress.org/Theme_Logo

Love when they add stuff like this, it means we can remove our custom controllers and rely on core WP features/documentation better.

1 Like
#2

this might help -> http://www.wpbeginner.com/news/whats-coming-in-wordpress-4-5-features-and-screenshots/

#3

It seems there’s some confusion with the docs and various blog posts about the topic.

Codex says it is: add_theme_support( 'custom-logo' );

https://codex.wordpress.org/Theme_Logo

Other places say: add_theme_support( 'site-logo' );

I think the one that works is custom-logo, so use that.

#4

and to show a default logo:

add_filter('get_custom_logo',function($html){
   if(empty($html)){ $html = '<img src="my default logo here">'; }
   return $html;
});
#5

nice share

#6

Hi, I used this code to try to set a DEFAULT logo in my theme but it’s not working.
Is there a problem with the syntax maybe - mix of " and ’ in the code.
Any ideas?
Thanks!

add_filter('get_custom_logo',function($html){
   if(empty($html)) { 
	 $html = '<img src = get_template_uri() . "/img/logo.jpg" >'; 
   } 
   return $html;
});
#7

try this

<?php
$logo_id = get_theme_mod( 'custom_logo' );
		$logo = wp_get_attachment_image_src( $logo_id , 'full' );
		$logo_path = get_template_directory_uri() . "/img/logo.png";

    							if( has_custom_logo() ) :
    								echo "<a href='". esc_url( home_url( '/' ) ) ."'>";
    								echo "<img src='". esc_url( $logo[0] ) ."' /></a>";
    							else :
    								echo "<a href='". esc_url( home_url( '/' ) ) ."'>";
    								echo "<img src='". esc_url( $logo_path ) ."' /></a>";
    							endif;
    						?>
#8

Hi mabuc,
Thanks for coming back.
I tried your code and it is progress - it does make the logo appear on the top left of the site - before any other content.
Unfortunately it doesn’t sit where the logo is.
It’s also messing up the backend slightly.

Seem to be close to a solution!

One hint is a warning I see:
Cannot modify header information - headers already sent by (output started at …/htdocs/wp-content/themes/mynewtheme/inc/setup.php:124)

#9

I used it on all of my themes and I have no problem with it. I think you should check your other codes that might cause your warning for header information.

#10

OK, I will have a look.
Thanks for your help mabuc!