Title: Custom hyperlinks with custom fields
Last modified: August 31, 2016

---

# Custom hyperlinks with custom fields

 *  [viriato_sueco](https://wordpress.org/support/users/viriato_sueco/)
 * (@viriato_sueco)
 * [10 years, 2 months ago](https://wordpress.org/support/topic/custom-hyperlinks-with-custom-fields/)
 * I have a situation where:
 * – I need to create a custom link per image on an image gallery. I have created
   a text field with HTML outputting so that hyperlinks get converted automatically.
   –
   The user will be populating that field with the link every time a new post is
   created. – I am using a custom post type (post-portfolio). – Each post has a 
   cover image that will be a thumbnail when looking at the gallery. – Those links
   will later on be displayed as a link on the thumbnail of the image – not on the
   image’s lightbox or single-post page. – The gallery’s default behavior is to 
   have two font-awesome icons acting as buttons/links: Lightbox view and single
   post permalink. I have now added a new font awesome link/button to have that 
   text field acting as the link’s target.
 * **The code on the functions.php:**
 *     ```
       if(function_exists("register_field_group"))
       {
       register_field_group(array (
       'id' => 'acf_sponsorer-lank',
       'title' => 'Sponsor hyperlänk',
       'fields' => array (
       array (
       'key' => 'field_56ea5ece13165',
       'label' => 'Sponsor länk till webbsida',
       'name' => 'sponsor_lank_till_webbsida',
       'type' => 'text',
       'instructions' => 'Skriv här webbsidan till sponsorn. Om det inte finns någon webbsida skriv endast #',
       'required' => 1,
       'default_value' => '',
       'placeholder' => '',
       'prepend' => '',
       'append' => '',
       'formatting' => 'html',
       'maxlength' => '',
       ),
       ),
       'location' => array (
       array (
       array (
       'param' => 'post_type',
       'operator' => '==',
       'value' => 'post-portfolio',
       'order_no' => 1,
       'group_no' => 1,
       ),
       ),
       ),
       'options' => array (
       'position' => 'normal',
       'layout' => 'default',
       'hide_on_screen' => array (
       ),
       ),
       'menu_order' => 0,
       ));
       }
       ```
   
 * **The code on the gallery that shows all thumbnails:**
 * `$variable = get_field('sponsor_lank_till_webbsida', $post->post-portfolio);`
 *     ```
       <div class="acts">
       <h3>'.get_the_title().'</h3>
       <a href="'.$url.'" title="'.get_the_title().'" class="icon-search" rel="prettyPhoto[gallery1]"><!----></a>
       <a href="'.the_field('sponsor_lank_till_webbsida', get_option('acf_sponsorer-lank')).'" class=" icon-h-link" target="_blank"><!----></a>
       <a href="'.get_permalink().'" class=" icon-link"><!----></a>
       </div>
       ```
   
 * **A note on the last bit of code I wrote:**
 * The `<div class="acts">` is inside of PHP tags, so no need to open and close 
   it there.
 * **Problem:**
 * The custom field is showing up where on the custom post type page when the admin
   creates a new post, but the link on the gallery page has no target (the value
   that the user inserts on the post creation page).
 * I have been reading the documentation and trying so many times and so many ways
   but I cannot seem to make it work. Can please somebody help me?

The topic ‘Custom hyperlinks with custom fields’ is closed to new replies.

## Tags

 * [ACF](https://wordpress.org/support/topic-tag/acf/)
 * [custom post type](https://wordpress.org/support/topic-tag/custom-post-type/)
 * [hyperlink](https://wordpress.org/support/topic-tag/hyperlink/)
 * [output](https://wordpress.org/support/topic-tag/output/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 0 replies
 * 1 participant
 * Last reply from: [viriato_sueco](https://wordpress.org/support/users/viriato_sueco/)
 * Last activity: [10 years, 2 months ago](https://wordpress.org/support/topic/custom-hyperlinks-with-custom-fields/)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
