How to display site logo using shortcode in wordPress?
We can display site header logo in a page or widget using shortcode in WordPress. For creating this shortcode we need get_custom_logo() and get_bloginfo(‘name’) function. Here is the code example:
You can check these function links:
https://developer.wordpress.org/reference/functions/get_bloginfo/
https://developer.wordpress.org/reference/functions/get_custom_logo/
function display_site_logo_shortcode() {
$logo_url = get_custom_logo(); // Retrieve logo URL (WordPress)
$site_text = get_bloginfo('name'); // Use site name as text
if ($logo_url) { // Check if a logo is set
return $logo_url;
} else {
return $site_text; // Or return site name if logo not uploaded
}
}
add_shortcode('site_logo', 'display_site_logo_shortcode');
Now add this shortcode in functions.php and insert this shortcode [site_logo] in any pages or widget of the site.