0

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?

0

First 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
  • Didn't work for me, url just comes up (unknown) – Xarcell May 5 at 12:56
  • You say the first part of code is missing some, what is it missing? – Xarcell May 5 at 13:07
  • this seems to work: echo esc_url(get_theme_mod('swag_header_logo')); – Xarcell May 5 at 13:14
  • 1
    It all depends what exactly do you store in that option and how do you process it. – Krzysiek Dróżdż May 5 at 13:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.