What is the correct way to display a value in a link using php?

The (Advanced Custom Fields) php works correctly outside of the html.

Book on Expedia.com <a class="alignright" href="<?php the_field( 'expedia' ); ?>" target="_blank" ><input class="resume_contact_button" type="button" value="<?php the_field( 'low_rate' ); ?>"></a>
  • just write echo after php tab like <?php echo the_field('...'); ?> – ksr89 May 22 '14 at 10:14
  • 1
    @ksr89 No need, the_... functions in ACF output the field already. – TheDeadMedic May 22 '14 at 10:19
  • Have tried a few alternative, no luck yet <?php echo field( 'low_rate' ); ?> – Muzza May 22 '14 at 10:43
  • am not able to understand your question. what do you mean by it works correctly outside of the html? – MortalViews May 22 '14 at 10:47
  • 1
    you don't need to use 'echo' with the_field. – MortalViews May 22 '14 at 10:56

If the function returns a printed value:

<a href="<?php bloginfo('url'); ?>">Link</a>

If not (using the echo statement):

<a href="<?php echo get_stylesheet_directory_uri(); ?>">Link</a>

You can also use print() as part of a more complex expression where echo cannot.

By the contrary, when you want to use HTML into PHP, I recommend to close PHP and open it again after the HTML code, instead of using echo "<a href='#'></a>"; like this example:

<?php my_function() { ?>
    <a href="<?php bloginfo('url'); ?>">Link</a>
<?php } ?>

Your PHP code is ok, but probably the function returns an empty value. Also, close the INPUT tag with />.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.