Skip to Content

logo()

Obtain the appropriate logo file from various locations.

PHP December 17, 2018

Usage

PHP
nebula()->logo()

Parameters

This function does not accept any parameters. Is this incorrect?

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

Source File

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

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'){
        //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) ){
            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
                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
                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
                return $this->get_thumbnail_src(get_theme_mod('one_color_logo'));
            }
        }

        return esc_url($logo);
    }

Override

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