Troubleshooting PHP-related issues in WordPress

Solution 1:

Update your code to correctly output the option values in the HTML:

<?php 
$hb = ot_get_option('home-banner'); 
$hbh = ot_get_option('home-banner-height'); 
?>

<div class="home-banner" style="background: url('<?php echo $hb; ?>'); <?php echo !empty($hbh) ? 'height:' . $hbh . 'px;' : ''; ?>">
</div>

Explanation:

1. Use instead of to output PHP variables.

2. Combine the height style inline after checking if the value exists.

Solution 2:

The issue likely occurs because you are using empty() on a function return:

!empty(ot_get_option('home-banner-height')) ? 'height:' . ... : '';

Fix:
Replace it with a direct check of the function return:

ot_get_option('home-banner-height') ? 'height:' . ... : '';

This removes the unnecessary !empty() and works correctly when the function returns a value.

Solution 3:

The issue is that your height value isn’t being echoed properly. Replace your code:

<div class="home-banner" style="background: url('<?= ot_get_option('home-banner'); ?>');
<?= !empty(ot_get_option('home-banner-height')) ? 'height:' . ot_get_option('home-banner-height') . 'px;' : ''; ?>">
</div>

with this:

<div class="home-banner" style="background: url('<?= ot_get_option('home-banner'); ?>');
<?php echo !empty(ot_get_option('home-banner-height')) ? 'height:' . ot_get_option('home-banner-height') . 'px;' : ''; ?>">
</div>

Explanation:

1. Use to output the height value.

2. In the original code, the ternary was evaluated but not printed.