Skip to Content
Menu

logo()

Obtain the appropriate logo file from various locations.

This is most useful for flexibility when you aren’t creating your own specific template files in the child theme (like footer.php). If you are building child theme templates, it might just be easier to hard-code the logo image locations or write your own functionality/logic entirely.

PHP December 5, 2023

Usage

PHP
nebula()->logo()

Parameters

$location
(Optional) (String) Where the logo appears (header, footer, meta)
Default: header

Request or provide clarification »

Examples

PHP
<img class="svg" src="<?php echo nebula()->logo(); ?>" alt="<?php bloginfo('name'); ?>"/>

Override all logos with one specific file (or run your own priority/logic here)

PHP
add_filter('nebula_logo', function(){
    return get_stylesheet_directory_uri() . '/override.jpg'
});

Change the default filename this function uses to look for logos in the parent and child theme directories (default: "logo"). This example would look for "gearside.svg" and "gearside.png" in both parent and child themes per priority list below.

PHP
add_filter('nebula_logo_filename', function(){
    return 'gearside' //Note: the function will look for .svg and .png so exclude the extension here.
});

Additional Notes

This function prioritizes in the following order:

  • A custom function that hooks into `nebula_logo` (an image file URL is the expected return)
  • Customizer on sub-page when that one-color logo checkbox is selected
  • Customizer on home page when that one-color logo checkbox is selected
  • Customizer full color logo
  • Child theme logo (SVG or PNG)
  • Parent theme logo (SVG or PNG)
  • false if none of the above are found
Was this page helpful? Yes No


    A feedback message is required to submit this form.


    Please check that you have entered a valid email address.

    Enter your email address if you would like a response.

    Thank you for your feedback!

    Source File

    Located in /libs/Functions.php on line 2169.

    2 Hooks

    Find these filters and actions in the source code below to hook into them. Use do_action() and add_filter() in your functions file or plugin.

    Filters
    "nebula_logo"
    "nebula_logo_filename"
    Need a new filter hook? Request one here.

    Actions
    This function has no action hooks available. Request one?

    PHP
            public function logo($location='header'){
                $timer_name = $this->timer('Finding Appropriate Logo (' . $location . ')');
    
                //Allow a theme or plugin to handle the logo itself. This assumes it does its own priorities or overrides for everything!
                $hooked_logo = apply_filters('nebula_logo', false);
                if ( !empty($hooked_logo) ){
                    $this->timer($timer_name, 'end');
                    return $hooked_logo;
                }
    
                $logo = false;
                $logo_filename = apply_filters('nebula_logo_filename', 'logo'); //Allow themes and plugins to set the logo filename to use. No extension here!
    
                //Search the parent theme for the logo file (SVG or PNG)
                if ( file_exists(get_template_directory() . '/assets/img/' . $logo_filename . '.svg') && $location !== 'meta' ){
                    $logo = get_template_directory_uri() . '/assets/img/' . $logo_filename . '.svg';
                } elseif ( file_exists(get_template_directory() . '/assets/img/' . $logo_filename . '.png') ){
                    $logo = get_template_directory_uri() . '/assets/img/' . $logo_filename . '.png';
                }
    
                //Search the child theme for the logo file (SVG or PNG)
                if ( file_exists(get_stylesheet_directory() . '/assets/img/' . $logo_filename . '.svg') && $location !== 'meta' ){
                    $logo = get_stylesheet_directory_uri() . '/assets/img/' . $logo_filename . '.svg';
                } elseif ( file_exists(get_stylesheet_directory() . '/assets/img/' . $logo_filename . '.png') ){
                    $logo = get_stylesheet_directory_uri() . '/assets/img/' . $logo_filename . '.png';
                }
    
                //If full color Customizer logo exists
                if ( get_theme_mod('custom_logo') ){
                    $logo = $this->get_thumbnail_src(get_theme_mod('custom_logo'));
                }
    
                //If it is the footer and the one-color logo (footer) is requested (checkbox)
                if ( $location === 'footer' && get_theme_mod('nebula_footer_single_color_logo') ){
                    if ( get_theme_mod('one_color_logo') ){ //If one-color Customizer logo exists
                        $this->timer($timer_name, 'end');
                        return $this->get_thumbnail_src(get_theme_mod('one_color_logo'));
                    }
                }
    
                //If it is the home page and the one-color logo (home) is requested (checkbox)
                if ( is_front_page() && get_theme_mod('nebula_hero_single_color_logo') && $location !== 'meta' ){
                    if ( get_theme_mod('one_color_logo') ){ //If one-color Customizer logo exists
                        $this->timer($timer_name, 'end');
                        return $this->get_thumbnail_src(get_theme_mod('one_color_logo'));
                    }
                }
    
                //If it a sub page and the one-color (sub) logo is requested (checkbox)
                if ( !is_front_page() && get_theme_mod('nebula_header_single_color_logo') && $location !== 'meta' ){
                    if ( get_theme_mod('one_color_logo') ){ //If one-color Customizer logo exists
                        $this->timer($timer_name, 'end');
                        return $this->get_thumbnail_src(get_theme_mod('one_color_logo'));
                    }
                }
    
                $this->timer($timer_name, 'end');
                return esc_url($logo);
            }
    

    Override

    This function can not be short-circuited with an override filter. Request one?