Steve Bower
Steve Bower

Reputation: 1

PHP variable in href in PHP

I'm struggling with the syntax of this:

echo '<strong><a href="<?php echo get_post_meta( get_the_ID(), 'data_sheet', true );?>" target="_blank">Datasheet</a></strong>';

The central PHP element gets a URL from a WooCommerce custom field (I know this works ok on its own). That needs to be turned into a viable link opening a new page, and the whole sits in a PHP wrapper on the page.

Where am I going wrong?

Upvotes: 0

Views: 431

Answers (2)

sicksixstrings
sicksixstrings

Reputation: 88

Try adding more to / changing the href

something like this might work

echo '<strong><a href="data_sheet.php?id='.$_GET['id'].'" target="_blank">Datasheet</a></strong>';

You'll have to adjust a little bit, but should do the trick

Upvotes: 1

Muhammad Usman
Muhammad Usman

Reputation: 1423

Try this hopefully, it will work.

echo '<strong><a href="' . get_post_meta( get_the_ID(), 'data_sheet', true ) . '" target="_blank">Datasheet</a></strong>';

Upvotes: 2

Related Questions