I'm trying to add a custom image setting to a custom panel/section for the header.
In functions.php, I used:
$wp_customize->add_setting('swag_header_logo');
$wp_customize->add_control(new WP_Customize_Upload_Control($wp_customize,'swag_header_logo',array(
'label' => __('Logo', 'frontend-theme'),
'section' => 'swag_header_content_section',
'settings' => 'swag_header_logo'
)));
Which shows up and seems to work in the customizer. However, when trying to get it to show up in the header, it gives the error:
Fatal error : Call to undefined function swag_header_logo() in /home/xxxxxx/public_html/wp-content/themes/frontend-theme/header.php on line 551
The code I used in the header.php:
$swag_header_logo = get_theme_mod('swag_header_logo');
and
<?php swag_header_logo(); ?>
How do I fix the error?
I'm trying to add a custom image setting to a custom panel/section for the header.
In functions.php, I used:
$wp_customize->add_setting('swag_header_logo');
$wp_customize->add_control(new WP_Customize_Upload_Control($wp_customize,'swag_header_logo',array(
'label' => __('Logo', 'frontend-theme'),
'section' => 'swag_header_content_section',
'settings' => 'swag_header_logo'
)));
Which shows up and seems to work in the customizer. However, when trying to get it to show up in the header, it gives the error:
Fatal error : Call to undefined function swag_header_logo() in /home/xxxxxx/public_html/wp-content/themes/frontend-theme/header.php on line 551
The code I used in the header.php:
$swag_header_logo = get_theme_mod('swag_header_logo');
and
<?php swag_header_logo(); ?>
How do I fix the error?
Share Improve this question asked May 5, 2019 at 11:01 XarcellXarcell 1035 bronze badges1 Answer
Reset to default 0First part of your code looks correct - it's hard to say if it will work, because it's only part of it, but there is nothing wrong with the part you've shown.
Problem lies in this line:
<?php swag_header_logo(); ?>
You haven't defined such function anywhere in your code, so you can't call it - and that's what the error is saying ("Call to undefined function swag_header_logo()").
So how to fix it?
In this line:
$swag_header_logo = get_theme_mod('swag_header_logo');
you get the ID of attachment set as swag_header_logo
and you store this ID in $swag_header_logo
variable.
So if you want to display the image, just use:
echo wp_get_attachment_image( $swag_header_logo, '<SIZE>' ); // change size to real value
or if you want only the URL of the image:
echo wp_get_attachment_image_url( $swag_header_logo, '<SIZE>' ); // change size to real value