Hi @japonsm
Thanks for reaching out. You can use the template tag just after the text.
Hi, thanks for your support.
I have inserted the code with this format:
<?php if(function_exists(‘rdv_category_image’)){
echo ‘Patrocinat per ‘;
rdv_category_image(); } ?>
The text appears correctly before the image. However, this text also appears on category pages where no image is defined.
With this code I’m trying to detect if the function returns an image so I can discard the text when it’s not needed:
<?php if(function_exists(‘rdv_category_image’)){
if ( true === rdv_category_image() ) {
echo ‘Patrocinat per ‘;
rdv_category_image();
}
} ?>
I have also tried this other way:
<?php if(function_exists(‘rdv_category_image’)){
if ( true === rdv_category_image() ) {
echo ‘Patrocinat per ‘ . rdv_category_image();
}
} ?>
In both cases the image is displayed but the text is not displayed.
How could I detect if the function returns an image so that I can discard the text when it’s not needed?
Thanks in advance.
Hi @japonsm
You can use this function rdv_category_image_url() to detect the image or image URL. Please check these two examples.
<?php if( function_exists('rdv_category_image_url') && !empty(rdv_category_image_url()) ){
echo 'Patrocinat per <img src="'.rdv_category_image_url().'">';
} ?>
<?php if( function_exists('rdv_category_image') && !empty(rdv_category_image_url()) ){
echo 'Patrocinat per ';
rdv_category_image();
} ?>
The proposed solution works perfectly.
Thank you,