LexLusa LexLusa - 1 year ago 68
PHP Question

Displaying an image via acf in the theme header

I am using AFC Pro and created an options pafe so tjhat the user can upload a new header logo whenever he wants to.

The ACF field is called "headerlogo".

What I want now is that the Logo gets replaced by my theme automatically.

My Variables are:

$headerlogo = wp_get_attachment_image_src(get_field('headerlogo', 'option'), 'full');

$default_logo = '<img src="'echo .$headerlogo[0].'" alt="SITE Logo">';

they get called in:

echo '<a href="'. esc_url( home_url( '/' ) ) .'">
' . $default_logo . '

But the Output is:

<a href="http://www.xxx.de/">
<img src="" alt="SITELogo">

What am I doing wrong here?
Thank in advance.

Answer Source

This should work:

$headerlogo = get_field('headerlogo');
if( !empty($headerlogo) ):
    $default_logo = '<img src="'. $headerlogo['url'] . '" alt="' . $headerlogo['alt'] . '" />';

echo '<a href="'. esc_url( home_url( '/' ) ) .'">' . $default_logo . '</a>';