Title: Inserting URL from Custom Field
Last modified: August 19, 2016

---

# Inserting URL from Custom Field

 *  Resolved [elijahn](https://wordpress.org/support/users/elijahn/)
 * (@elijahn)
 * [15 years, 11 months ago](https://wordpress.org/support/topic/inserting-url-from-custom-field/)
 * I’m trying to insert a unique(to each post) URL at the end of each post. The 
   URL is stored in a custom field. I have tried the following:
 *     ```
       <?php
       $link = get_post_meta($post->ID, 'custom_field_name', true);
       if ($link){
         echo '<a href="'.$link .'">Visit this site.</a>';
       }
       ?>
       ```
   
 * and
 *     ```
       <a href="<?php echo get_post_meta($post->ID, "custom_field_name", true); ?>">Visit this site.</a>
       ```
   
 * Both of these codes have resulted in the URL being displayed with my domain attached
   to the beginning so it looks like:
 * `http://www.mydomain42342.com/www.thedomaininthecustomfield.com/news/topic.html`
 * Instead of the intended:
 * `www.thedomaininthecustomfield.com/news/topic.html`
 * How do I fix this?
 * Thanks!
 * Elijah

Viewing 3 replies - 1 through 3 (of 3 total)

 *  [Mark / t31os](https://wordpress.org/support/users/t31os_/)
 * (@t31os_)
 * [15 years, 11 months ago](https://wordpress.org/support/topic/inserting-url-from-custom-field/#post-1524519)
 * You only need make sure you include the `http://` when you put an address into
   the custom field, else the link is assumed to be relative to the current site.
 * However you could just conditionalise the custom field code, adding the `http://`
   when necessary, here’s a basic example..
 *     ```
       if( $link ) {
       	$link = esc_url( $link );
       	if( substr( $link , 0 , 7 ) != 'http://' )
       		$link = 'http://' . $link;
       	echo '<a href="'.$link .'">Visit this site.</a>';
       }
       ```
   
 *  Thread Starter [elijahn](https://wordpress.org/support/users/elijahn/)
 * (@elijahn)
 * [15 years, 11 months ago](https://wordpress.org/support/topic/inserting-url-from-custom-field/#post-1524613)
 * Thanks! That was the problem.
 *  [bobpatel](https://wordpress.org/support/users/bobpatel/)
 * (@bobpatel)
 * [15 years, 7 months ago](https://wordpress.org/support/topic/inserting-url-from-custom-field/#post-1524807)
 * I have a quick question on safetynewstoday.com, how can l get it to show a unique
   url like safetynewstoday.com/categoryname/article name
 * instead of
 * [http://www.safetynewstoday.com/?cat=235](http://www.safetynewstoday.com/?cat=235)
 * Today is my 7th day bday using WordPress, l got it to work on this site
 * [http://visaliamarketinggroup.com](http://visaliamarketinggroup.com)

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘Inserting URL from Custom Field’ is closed to new replies.

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 3 replies
 * 3 participants
 * Last reply from: [bobpatel](https://wordpress.org/support/users/bobpatel/)
 * Last activity: [15 years, 7 months ago](https://wordpress.org/support/topic/inserting-url-from-custom-field/#post-1524807)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
