How to add a custom logo to my WordPress theme

Michael B Dec 16, 2024 Theme Customization
How do I put my own logo on my website?
What are the steps to integrate a custom logo into a WordPress theme using the customizer and theme support?
Andy answered Dec 16, 2024

Adding a Custom Logo to WordPress - Step by Step Guide

Method 1: Using WordPress Native Logo Support

The recommended way to add a custom logo is using WordPress's built-in logo functionality:

  1. First, add theme support for custom logos in your theme's functions.php:
function mytheme_setup() {
    add_theme_support('custom-logo', array(
        'height'      => 100,
        'width'       => 400,
        'flex-height' => true,
        'flex-width'  => true,
        'header-text' => array('site-title', 'site-description'),
    ));
}
add_action('after_setup_theme', 'mytheme_setup');
  1. Add this code to your header template (usually header.php):
<?php
if (has_custom_logo()) {
    the_custom_logo();
} else {
    echo '<h1>' . get_bloginfo('name') . '</h1>';
}
?>

Method 2: Through WordPress Customizer

Once you've added theme support, you can upload your logo:

  1. Go to Appearance → Customize
  2. Look for "Site Identity" or "Logo"
  3. Click "Select logo"
  4. Upload your image or choose from Media Library
  5. Crop if needed and save

Best Practices

  • Use SVG or PNG format for logos (SVG preferred for scalability)
  • Keep file size under 100KB for optimal loading
  • Recommended dimensions: 200-400px width, maintaining aspect ratio
  • Include fallback text for accessibility
  • Test logo appearance on both desktop and mobile

Common Pitfalls to Avoid

  • Don't hardcode logo dimensions in CSS
  • Avoid using img tags directly in template files
  • Don't forget to add responsive styling
  • Make sure logo is visible against your background

Security Considerations

  • Only allow authorized users to modify the logo
  • Implement proper file type validation
  • Use WordPress's built-in media handling for uploads
  • Keep backups of your logo files

CSS Tips

Add this CSS to your theme's stylesheet for better logo control:

.custom-logo-link {
    max-width: 300px;
    height: auto;
    display: inline-block;
}

.custom-logo {
    width: 100%;
    height: auto;
}

Alternative Solutions

If you need more advanced logo management features, consider these plugins:

  1. Multiple Logo - Allows different logos for various device sizes
  2. Header Footer Code Manager - Helpful for adding custom logo code in header

Mobile Considerations

  • Consider using different logo sizes for mobile devices
  • Test logo visibility across different screen sizes
  • Ensure logo doesn't overflow on small screens
  • Use CSS media queries for responsive adjustments

By following these steps and best practices, you'll have a professional-looking logo that works well across all devices and maintains your brand identity consistently throughout your WordPress site.