1

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>
9
  • just write echo after php tab like <?php echo the_field('...'); ?>
    – ksr89
    May 22, 2014 at 10:14
  • 1
    @ksr89 No need, the_... functions in ACF output the field already. May 22, 2014 at 10:19
  • Have tried a few alternative, no luck yet <?php echo field( 'low_rate' ); ?>
    – Muzza
    May 22, 2014 at 10:43
  • am not able to understand your question. what do you mean by it works correctly outside of the html? May 22, 2014 at 10:47
  • 1
    you don't need to use 'echo' with the_field. May 22, 2014 at 10:56

1 Answer 1

1

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 />.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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