Reputation: 3
I'm using the wpjobmanager plugin.
There's a field called 'company logo' that displays a default logo on every job. I'm trying to disable it and only show a logo when a user has specifically uploaded one.
I created this IF statement, but for some reason, the default logo is not considered empty so it continues to display it. I've tried null too and get the same result.
$is_logo = get_post($post->ID, '_company_logo', true);
if (!empty($is_logo)) {
the_company_logo();
}
Could someone point me in the right direction here? I'm at a loss.
Thanks
Upvotes: 0
Views: 66
Reputation: 5639
Here is the code for get_the_company_logo which returns empty string if not set.
/**
* Gets the company logo.
*
* @since 1.0.0
* @param int|WP_Post $post (default: null).
* @param string $size
* @return string Image SRC.
*/
function get_the_company_logo( $post = null, $size = 'thumbnail' ) {
$post = get_post( $post );
if ( has_post_thumbnail( $post->ID ) ) {
$src = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), $size );
return $src ? $src[0] : '';
} elseif ( ! empty( $post->_company_logo ) ) {
// Before 1.24.0, logo URLs were stored in post meta.
return apply_filters( 'the_company_logo', $post->_company_logo, $post );
}
return '';
}
So if you did
if (!empty(get_the_company_logo($post->ID)){
the_company_logo();
}
This would seem like it should work. I am not using this plugin, so I can't really test this.
Upvotes: 1
Reputation: 166
Try this the_company_logo()
function:
if(!empty(the_company_logo())) {
get_the_company_logo()
}
I read this function here -> https://wpjobmanager.com/document/template-tags/.
Say me if you need some help.
Upvotes: 0