admin管理员组文章数量:1429101
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
本文标签: Adding Custom Image To Header Via New Customizer Setting
版权声明:本文标题:Adding Custom Image To Header Via New Customizer Setting 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745522873a2661706.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论