0

So I have a custom field on the author page, where a user uploads a image which will be used as a background image on their author page. I've setup up everything except I'm not sure how to setup a conditional to display a default image when the user hasn't upload his/her own image.

The custom $curauth-> field is called user_banner.

So basically:

[if user_banner]

The image would be displayed here.

[else]

The default image would go here.

[end]

Any ideas?

0

A combination of get_queried_object_id to fetch the current user ID and get_user_meta to retrieve the banner should do the trick.

<?php
// somewhere in your theme's author.php

if ($img = get_user_meta(get_queried_object_id(), 'user_banner', true)) {
   // they uploaded an image, use it
} else {
   // they did not upload the image, show the default
}

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.