Title: Adding Link to Label in PHP
Last modified: August 18, 2019

---

# Adding Link to Label in PHP

 *  [kcarissimi](https://wordpress.org/support/users/kcarissimi/)
 * (@kcarissimi)
 * [6 years, 8 months ago](https://wordpress.org/support/topic/adding-link-to-label-in-php/)
 * Hi all,
 * I am working with a template that displays the custom taxonomy “Tracks” under“
   Sessions.” These appear as a label, as you can see above. I’d like the labels
   to link to all the sessions tagged with the same. This is the PHP I am working
   with:
 * `<span data-track="<?php echo $track->term_id; ?>" class="label single-session-
   link btn btn-primaryd<?php if (empty($track->color)) echo " bg-gold"; ?>" <?php
   if (!empty($track->color)) echo "style='background-color: $track->color;'"; ?
   >><?php echo $track->name; ?> </span>`
 * I am trying to add “get permalink” and direct it to the slug but I am really 
   not well versed in writing PHP. Please assist.
    -  This topic was modified 6 years, 8 months ago by [Jan Dembowski](https://wordpress.org/support/users/jdembowski/).
    -  This topic was modified 6 years, 8 months ago by [bcworkz](https://wordpress.org/support/users/bcworkz/).
      Reason: code fixed
 * The page I need help with: _[[log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fwordpress.org%2Fsupport%2Ftopic%2Fadding-link-to-label-in-php%2F%3Foutput_format%3Dmd&locale=en_US)
   to see the link]_

Viewing 1 replies (of 1 total)

 *  Moderator [bcworkz](https://wordpress.org/support/users/bcworkz/)
 * (@bcworkz)
 * [6 years, 8 months ago](https://wordpress.org/support/topic/adding-link-to-label-in-php/#post-11843047)
 * To “linkify” any block of output code using get_permalink(), you wrap it in an
   anchor tag like so:
 *     ```
       <a href="<?php echo get_permalink(); ?>">
       --- your code block goes here ---
       </a>
       ```
   
 * The resulting link isn’t going to have the effect you want though. get_permalink()
   returns a link to the current post in the loop. In the example page you linked,
   it will simply link to the same page. You want to link to a taxonomy term archive
   such as _example.com/tracks/my-track/_.
 * Assuming your `$track` is a proper term object, replace `get_permalink()` with`
   get_term_link( $track )`
 * FYI, it’s helpful if you delimit any code you post in these forums with backticks,
   or use the code button. If you don’t do so, the forum’s parser corrupts your 
   code. I fixed the code you posted.

Viewing 1 replies (of 1 total)

The topic ‘Adding Link to Label in PHP’ is closed to new replies.

## Tags

 * [css](https://wordpress.org/support/topic-tag/css/)
 * [development](https://wordpress.org/support/topic-tag/development/)
 * [permalink](https://wordpress.org/support/topic-tag/permalink/)
 * [php](https://wordpress.org/support/topic-tag/php/)
 * [templates](https://wordpress.org/support/topic-tag/templates/)

 * In: [Developing with WordPress](https://wordpress.org/support/forum/wp-advanced/)
 * 1 reply
 * 2 participants
 * Last reply from: [bcworkz](https://wordpress.org/support/users/bcworkz/)
 * Last activity: [6 years, 8 months ago](https://wordpress.org/support/topic/adding-link-to-label-in-php/#post-11843047)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
