admin管理员组

文章数量:1302318

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 <a class="alignright" href="<?php the_field( 'expedia' ); ?>" target="_blank" ><input class="resume_contact_button" type="button" value="<?php the_field( 'low_rate' ); ?>"></a>

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 <a class="alignright" href="<?php the_field( 'expedia' ); ?>" target="_blank" ><input class="resume_contact_button" type="button" value="<?php the_field( 'low_rate' ); ?>"></a>
Share Improve this question asked May 22, 2014 at 10:11 MuzzaMuzza 251 silver badge7 bronze badges 9
  • just write echo after php tab like <?php echo the_field('...'); ?> – ksr89 Commented May 22, 2014 at 10:14
  • 1 @ksr89 No need, the_... functions in ACF output the field already. – TheDeadMedic Commented May 22, 2014 at 10:19
  • Have tried a few alternative, no luck yet <?php echo field( 'low_rate' ); ?> – Muzza Commented 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? – MortalViews Commented May 22, 2014 at 10:47
  • 1 you don't need to use 'echo' with the_field. – MortalViews Commented May 22, 2014 at 10:56
 |  Show 4 more comments

1 Answer 1

Reset to default 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 />.

本文标签: advanced custom fieldsDisplay PHP within HTML values