0

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?

1
  • What do you get at the moment when that code runs? Commented Jun 8, 2017 at 0:49

2 Answers 2

2

Try this hopefully, it will work.

echo '<strong><a href="' . get_post_meta( get_the_ID(), 'data_sheet', true ) . '" target="_blank">Datasheet</a></strong>';
Sign up to request clarification or add additional context in comments.

1 Comment

@SteveBower Glad to help ;) please marked tick the answer
1

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

3 Comments

This isn't going to work. You're already in PHP mode, so the string should be concated. You can't echo inside echo
You are right, I just edited the answer to remove the PHP tags
Slightly incorrect still, I corrected it for you. This will print correctly and shouldn't throw syntax errors

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.