-2

I have a problem with the below code. How do I put html code into //do nothing;'s place?

<?php 
  $matnmusic = get_post_meta($post->ID, 'matnmusic', true);
  if ($matnmusic) { ?>
<p><h3><div class="matn-ms" style="text-align: center ; color: #400361 "> <? echo $matnmusic; ?></h3></p>
<?php 
  } else { 
     // do nothing;
  }
?>

I have tried as below, but this code gives an error:

<?php 
  $matnmusic = get_post_meta($post->ID, 'matnmusic', true);
  if ($matnmusic) { ?>
<p><h3><div class="matn-ms" style="text-align: center ; color: #400361 "> <? echo $matnmusic; ?></h3></p>
<?php 
  } else { 
<center><span id="button"><a title="lyrics" href="/send-lyric/" style="color:#FFF;">lyrics</a></span></center>
  }
?>
ItsPete
  • 2,363
  • 3
  • 27
  • 35
Fara Music
  • 13
  • 2

1 Answers1

1

I tried with your code and it also didn't work. But I made some changes and now it should work because it is working for me. Since you added style=color:#FFF; in <a> tag the result is not showing because the background is also white. And also instead of <? echo $matnmusic; ?>, use <?= $matnmusic; ?> or <?php echo $matnmusic; ?>. Now it should work in case if there is a problem with the following statement.

get_post_meta($post->ID, 'matnmusic', true);

So you can just try that if your HTML is working or not by removing the above statement and add $matnmusic = false or true. Then it will work. Hope this helps you.

<?php 

$matnmusic = get_post_meta($post->ID, 'matnmusic', true);

if ($matnmusic) { ?>

<p>
    <h3>
        <div class="matn-ms" style="text-align:center; color: #400361;"> 
            <?= $matnmusic; ?>
    </h3>
</p>

<?php } else { ?>

<center>
    <span id="button">
        <a title="lyrics" href="/send-lyric/" style="color:red;">lyrics</a>
    </span>
</center>

<?php } ?>
Hasitha Jayawardana
  • 2,326
  • 4
  • 18
  • 36