Displaying an image via acf in the theme header

时间:2016-08-31 17:22:52

标签: php wordpress advanced-custom-fields

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 . '
        </a>';

But the Output is:

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

What am I doing wrong here? Thank in advance.

1 个答案:

答案 0 :(得分:1)

This should work:

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


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