Title: Insert variable into URL
Last modified: August 21, 2016

---

# Insert variable into URL

 *  Resolved [tmeche87](https://wordpress.org/support/users/tmeche87/)
 * (@tmeche87)
 * [12 years, 8 months ago](https://wordpress.org/support/topic/insert-variable-into-url/)
 * Hey I’m trying to concatenate two variables and use them to within a URL. However,
   it hasn’t been working and I’ve tried several different methods.
    Here is my 
   current code that I am trying to use, but it’s not working.
 *     ```
       <?php $proj_tit = get_post_meta($post->ID, 'wpcf-project-title', true) ?>
       	<?php $proj_title = str_replace(" ", "-", $proj_tit) ?>
       	<?php $custurl = "http://www.webdev.blabla.org/projects/" ?>
       	<?php echo ('<a href="$custurl . $proj_title">$proj_tit</a>') ?>
       ```
   
 * $proj_tit is getting the value “Malware Evolution”
    $proj_title is getting the
   value “malware-evolution” $custurl is getting the value “[http://www.webdev.blabla.org/projects/&#8221](http://www.webdev.blabla.org/projects/&#8221);
 * 
 * With this code, my URL is this:
    [http://webdev.blabla.org/projects/$custurl.$proj_title](http://webdev.blabla.org/projects/$custurl.$proj_title)
 * I want it to look like this:
    [http://webdev.blabla.org/projects/malware-evolution](http://webdev.blabla.org/projects/malware-evolution)
 * I’m not sure why but the link is autmatically getting the “[http://webdev.blabla.org/projects&#8221](http://webdev.blabla.org/projects&#8221);
   part of the URL from somwhere. It’s not getting this from my $custurl variable.
 * Can anybody please help me? I’m lost as to what I should do.

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

 *  [Boris Kuzmanov](https://wordpress.org/support/users/kuzmanov/)
 * (@kuzmanov)
 * [12 years, 8 months ago](https://wordpress.org/support/topic/insert-variable-into-url/#post-3959847)
 *     ```
       <?php echo '<a href="'.$custurl.''.$proj_title.'">'.$proj_tit.'</a>'; ?>
       ```
   
 * So, if your variables have values like this:
    $custurl = “[http://www.webdev.blabla.org/projects/&#8221](http://www.webdev.blabla.org/projects/&#8221);;
   $proj_title = “MyProject”; $proj_tit = “Link Title”;
 * the output will be
 *     ```
       <a href="http://www.webdev.blabla.org/projects/MyProject">Link Title</a>
       ```
   
 *  Thread Starter [tmeche87](https://wordpress.org/support/users/tmeche87/)
 * (@tmeche87)
 * [12 years, 8 months ago](https://wordpress.org/support/topic/insert-variable-into-url/#post-3959922)
 * Thanks Boris! You were a big help!

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

The topic ‘Insert variable into URL’ is closed to new replies.

## Tags

 * [concatenate](https://wordpress.org/support/topic-tag/concatenate/)
 * [url](https://wordpress.org/support/topic-tag/url/)
 * [variable](https://wordpress.org/support/topic-tag/variable/)

 * In: [Hacks](https://wordpress.org/support/forum/plugins-and-hacks/hacks/)
 * 2 replies
 * 2 participants
 * Last reply from: [tmeche87](https://wordpress.org/support/users/tmeche87/)
 * Last activity: [12 years, 8 months ago](https://wordpress.org/support/topic/insert-variable-into-url/#post-3959922)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
