Title: Getting the the permalink into a variable ?
Last modified: August 18, 2016

---

# Getting the the permalink into a variable ?

 *  Resolved [dizzy100](https://wordpress.org/support/users/dizzy100/)
 * (@dizzy100)
 * [18 years, 8 months ago](https://wordpress.org/support/topic/getting-the-the-permalink-into-a-variable/)
 * OK i’m not expecting a great deal of help considering all my other posts have
   remained unanswered but here goes anyway 🙂
 * OK i’m coding a routine to go into template.php and everything is working great.
 * However how do i get the real life permalink of the post.
 * I’ve tried using
 * **$post->guid** but that’s storing some weird old paths (i.e. [http://localhost](http://localhost)
   as well as other variants). Ironically however wordpress is displaying, using
   the **the_permalink ()** function in normal templates, just right.
 * So i tried (within my loop) to capture that as a string using
 *     ```
       <strong>ob_start();
       the_permalink ();
       $link= ob_get_contents();
       ob_end_clean();</strong>
       ```
   
 * But although that works in say the home.php template it refuses to work in my
   templates.php under my function.
 * I have every other variable i need working in that function apart from the permalink.
   Anyone any ideas how i can get it to read that into a variable so i can output
   it into a a href within my function ?
 * I even looked (and failed) to find the the_permalink () function in the wordpress
   php files.
 * I really need help on this one guys.

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

 *  Thread Starter [dizzy100](https://wordpress.org/support/users/dizzy100/)
 * (@dizzy100)
 * [18 years, 8 months ago](https://wordpress.org/support/topic/getting-the-the-permalink-into-a-variable/#post-632262)
 * Glad to see all this support here 🙂
 * Anyway i solved it today.
 * Use the function **get_permalink()** and pass it the post ID.
 * So
 * `<strong>get_permalink($post->ID)</strong>`
 * Put in a loop of your SQL query will output the correct permalink to the posts
   your calling.
 *  Thread Starter [dizzy100](https://wordpress.org/support/users/dizzy100/)
 * (@dizzy100)
 * [18 years, 8 months ago](https://wordpress.org/support/topic/getting-the-the-permalink-into-a-variable/#post-632263)
 * oops that  shouldn’t have been there.
 * Just use
 * **get_permalink($post->ID)**

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

The topic ‘Getting the the permalink into a variable ?’ is closed to new replies.

 * 2 replies
 * 1 participant
 * Last reply from: [dizzy100](https://wordpress.org/support/users/dizzy100/)
 * Last activity: [18 years, 8 months ago](https://wordpress.org/support/topic/getting-the-the-permalink-into-a-variable/#post-632263)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
