Title: Pulling variable from the_permalink?
Last modified: August 19, 2016

---

# Pulling variable from the_permalink?

 *  [lilqhgal](https://wordpress.org/support/users/lilqhgal/)
 * (@lilqhgal)
 * [16 years, 7 months ago](https://wordpress.org/support/topic/pulling-variable-from-the_permalink/)
 * I’m trying to hard-code the permalink into a php call but for the life of me 
   can’t find the correct format to use. I’m echoing a string of html so obviously
   can’t simply stick `<?php the_permalink() ?>` in there. It has to look something
   like `$link = get_post_meta($post->ID, 'the_permalink', true);` but that’s not
   working for me. Can anyone point me in the right direction? Thanks!

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

 *  [esmi](https://wordpress.org/support/users/esmi/)
 * (@esmi)
 * [16 years, 7 months ago](https://wordpress.org/support/topic/pulling-variable-from-the_permalink/#post-1260877)
 * [http://codex.wordpress.org/Template_Tags/get_permalink](http://codex.wordpress.org/Template_Tags/get_permalink)?
 *  Thread Starter [lilqhgal](https://wordpress.org/support/users/lilqhgal/)
 * (@lilqhgal)
 * [16 years, 7 months ago](https://wordpress.org/support/topic/pulling-variable-from-the_permalink/#post-1260881)
 * Thanks esmi, but I already read thru that and it’s not helping. I should clarify
   my issue… I’m trying to create a link inside some php that outputs some html 
   via the echo command from a category level page. Anywhere else in the template
   file, I can simply use `<?php the_permalink() ?` but putting that in my echo 
   line breaks the php. I need a way to grab the permalink and stick it into a variable
   so it won’t break the echo line. Here’s the main chunk of my code below:
 *     ```
       <?php //if custom field is present, formulate and display html from meta value
       $proj_img_thumb = get_post_meta($post->ID, 'proj_img_thumb', true);
       $link = get_post_meta($post->ID, 'the_permalink', true);
       if ($proj_img_thumb){
       echo '<a href="'.$link.'"><img src="'.$proj_img_thumb .'" /></a>';
       }
       ?>
       <a href="<?php the_permalink() ?>" title="<?php the_title_attribute(); ?>">Learn more about <?php the_title(); ?>.</a>
       ```
   
 *  [esmi](https://wordpress.org/support/users/esmi/)
 * (@esmi)
 * [16 years, 7 months ago](https://wordpress.org/support/topic/pulling-variable-from-the_permalink/#post-1260886)
 * Is this link meant to the current post’s slug or a url from a custom field attached
   to the current post?
 *  Thread Starter [lilqhgal](https://wordpress.org/support/users/lilqhgal/)
 * (@lilqhgal)
 * [16 years, 7 months ago](https://wordpress.org/support/topic/pulling-variable-from-the_permalink/#post-1260980)
 * It would be to link to the post’s slug. I am no programmer (I know enough to 
   break stuff but not enough to fix LOL) so I copied what was working (the custom
   field php stuff) and tried to modify it for my needs. Obviously I screwed it 
   up. *sheepish grin*
 * Basically …. I need to make the output of `<?php the_permalink() ?>` into my 
   variable `$link`
 * Thanks so far!
 *  [esmi](https://wordpress.org/support/users/esmi/)
 * (@esmi)
 * [16 years, 7 months ago](https://wordpress.org/support/topic/pulling-variable-from-the_permalink/#post-1260999)
 * get_permalink: Returns the permalink to a post for use in PHP. It does NOT display
   the permalink and can be used outside of The Loop.
 * Seems ideal for your use.
 *  Thread Starter [lilqhgal](https://wordpress.org/support/users/lilqhgal/)
 * (@lilqhgal)
 * [16 years, 7 months ago](https://wordpress.org/support/topic/pulling-variable-from-the_permalink/#post-1261036)
 * I had to try a few different things but what ended up working was:
    `$permalink
   = get_permalink($post->ID);`
 * Thanks for the nudge in the right direction (and being patient!) esmi!

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

The topic ‘Pulling variable from the_permalink?’ is closed to new replies.

## Tags

 * [permalink](https://wordpress.org/support/topic-tag/permalink/)
 * [variables](https://wordpress.org/support/topic-tag/variables/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 6 replies
 * 2 participants
 * Last reply from: [lilqhgal](https://wordpress.org/support/users/lilqhgal/)
 * Last activity: [16 years, 7 months ago](https://wordpress.org/support/topic/pulling-variable-from-the_permalink/#post-1261036)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
