get_header_image()

Description

Retrieves the header image URL based on the user's appearance preference and system configuration.

Parameters

ColumnTypeDefaultDescription
$full bool false Whether to return the full URL including the base URL.
$for_header bool false Whether the image is being displayed in the header.
$force_appearance string "": string { global $linkedheaderimgsrc Optionally force the appearance mode ('dark' or 'light').
$linkedheaderimgsrc_dark
$baseurl_short
$baseurl
$storageurl
$user_pref_appearance;

Return

string The resolved URL for the header image.

Location

include/config_functions.php lines 1469 to 1528

Definition

 
function get_header_image(bool $full falsebool $for_header falsestring $force_appearance ""): string
{
    global 
$linkedheaderimgsrc$linkedheaderimgsrc_dark$baseurl_short$baseurl$storageurl$user_pref_appearance;

    
$css_color_scheme $_COOKIE['css_color_scheme'] ?? 'light';

    
// Use custom header image
    
if (trim($linkedheaderimgsrc) != "" || trim($linkedheaderimgsrc_dark) != "") {
        if (
$force_appearance == "dark") {
            
$header_img_src trim($linkedheaderimgsrc_dark) != "" $linkedheaderimgsrc_dark $linkedheaderimgsrc;
        } elseif (
$force_appearance == "light") {
            
$header_img_src trim($linkedheaderimgsrc) != "" $linkedheaderimgsrc $linkedheaderimgsrc_dark;
        } elseif (
$user_pref_appearance == "light" && trim($linkedheaderimgsrc) != "") {
            
$header_img_src $linkedheaderimgsrc;
        } elseif (
$user_pref_appearance == "dark" && trim($linkedheaderimgsrc_dark) != "" || ($user_pref_appearance == "device" && $css_color_scheme == "dark")) {
            
$header_img_src $linkedheaderimgsrc_dark;
        } else {
            
$header_img_src trim($linkedheaderimgsrc) != "" $linkedheaderimgsrc $linkedheaderimgsrc_dark;
        }

        if (
substr($header_img_src04) !== 'http') {
            
// Set via System Config page?
            
if (substr($header_img_src013) == '[storage_url]') {
                
// Parse and replace the storage URL
                
$header_img_src str_replace('[storage_url]'$storageurl$header_img_src);
            } else {
                
// Set via config.php
                // if image source already has the baseurl short, then remove it and add it here
                
if (substr($header_img_src01) === '/') {
                    
$header_img_src substr($header_img_src1);
                }

                
$header_img_src $baseurl_short $header_img_src;
            }

            if (
$full && substr($header_img_src01) === '/') {
                
$header_img_src $baseurl substr($header_img_src1);
            }
        }
    } else {
        
// Use default ResourceSpace logo
        
if ($for_header) {
            
// If displaying in header then take into account user appearance preference
            
if ($force_appearance == "dark") {
                
$header_img_src $baseurl '/gfx/titles/title.svg';
            } elseif (
$force_appearance == "light") {
                
$header_img_src $baseurl '/gfx/titles/title-black.svg';
            } elseif (
$user_pref_appearance == 'dark' || ($user_pref_appearance == "device" && $css_color_scheme == "dark")) {
                
$header_img_src $baseurl '/gfx/titles/title.svg';
            } else {
                
$header_img_src $baseurl '/gfx/titles/title-black.svg';
            }
        } else {
            
// When displaying in other places simply return the default logo
            
$header_img_src $baseurl '/gfx/titles/title-black.svg';
        }
    }

    return 
$header_img_src;
}

This article was last updated 22nd April 2025 13:35 Europe/London time based on the source file dated 17th April 2025 16:15 Europe/London time.