Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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?

share|improve this question
add comment

1 Answer

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
}
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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