0

I am a little stuck in one situation. I am removing some errors from my site and got one unexpected error here below is my code:-

<?PHP
$release_web_url = get_post_meta( get_the_ID(), '_links', true );
print_r($release_web_url) ; ?>

and the output of this code is:

Array ( [0] => Array ( [name] => Website [url] =>www.google.com ) ) 

I only want to echo the array URL value in the anchor HTML tag. So I did this coding below:

foreach($release_web_url as $item): ?>
    <a href="<?php echo $item['url']; ?>">Website</a>
<?php endforeach;

now instead of getting anchor link = www.google.com | I got anchor link = 192.168.1.50/jobifylocal/www.google.com | that thing doesn't make any sense adding the other URL automatically in-front of the given URL.

1
  • If you look at the source code of the page, you'll see <a href="www.google.com">, the browser is showing you were that leads, it's not a WP bug, see Jacobs answer for why and how to fix it
    – Tom J Nowell
    Sep 2, 2020 at 12:11

1 Answer 1

2

You’ve forgotten the https://. This will happen in any HTML where you don’t add the protocol to a URL. Nothing to do with WordPress.

However, you should use esc_url() when outputting user entered values into a link, to make sure the output is a valid URL, even if the user makes this same mistake:

<a href="<?php echo esc_url( $item['url'] ); ?>">Website</a>
1

Your Answer

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

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