如果默认值为空,Wordpress PHP将使用网站标题替换图像

I am making options in the 'customization api' for Wordpress. However for things such as the logo image, if no image has been uploaded (default value is blank) i want it to display the title of the Wordpress site. I have searched google a lot, but I just cant seem to get it to work.

I know the PHP code for the Wordpress site title, but I can't get the php 'if' and 'else' to work.

current code:

<img src="<?php echo get_theme_mod('logo_image'); ?>" alt="<?php bloginfo('name'); ?>"/>

..obviously this is just the option to upload the image, which WORKS, but I want it to display the site title if the default value is empty.

Thank you!

I don't know how you are setting the theme mod. I.e. are you using 'set_theme_mod' ?

But assuming you are complying to WordPress standards the code snippet below should be what you are seeking.

if (!empty(get_theme_mod('logo_image'))) {
    echo "<img src='" . get_theme_mod('logo_image') . "' title='" . bloginfo('name') ."'>"
} else {
    echo "<h2>" . bloginfo('name') . "</h2>";
}

Hope this helps you out, Dave.

Can you try this?

<img src="<?php if (!isset(get_theme_mod['logo_image'])) {
    echo ('Your custom image');
}
else{
    echo get_theme_mod('logo_image');
}
?>" alt="<?php bloginfo('name'); ?
>"/>