skip to Main Content

I have the following code:

if( get_field('event_timedate') ): echo "<div class='bm-event_timedate'><p>".the_field('event_timedate')."</p></div>"; endif;

But for some reason the output is (the date appears before the div and p tags)

27/08/2022 8:00pm <div class='bm-event_timedate'><p>".the_field('event_timedate')."</p></div>

Id really appreciate any help, thanks in advance!

2

Answers


  1. use get_field() function for echo as well

    if( get_field('event_timedate') ):
        echo "<div class='bm-event_timedate'><p>".get_field('event_timedate')."</p></div>"; 
    endif;
    
    Login or Signup to reply.
  2. The issue is due to the_field()
    this function itself displays data but you insert the display data function inside echo.

    either you can do like

    if( get_field('event_timedate') ):
      echo "<div class='bm-event_timedate'><p>";
      the_field('event_timedate');
      echo "</p></div>";
    endif; 
    

    OR

    you can use get_field() function instead of the_field() function;

    if( get_field('event_timedate') ):
       echo "<div class='bm-event_timedate'><p>". get_field ('event_timedate')."</p></div>";
    endif; 
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search