I want to link content comprised of a custom field(field1_details) using another custom field(field2_link) which is a URL type. the_field('field1_details') is text_area field and get_field('field2_link') is a website field (using a ACF addon).

(These custom fields are created using Advanced custom fields plugin)

Here is the code I am trying in loop.php:

<span class="c_f"><a href="<?php get_field('field2_link'); ?>"><?php if( function_exists('the_field') ) the_field('field1_details'); ?></a></span>


 <a href="">The text content</a> ( Doesn't out put the link)

And tried this without the if

<span class="c_f"><a href="<?php get_field('field2_link'); ?>"><?php the_field('field1_details'); ?></a></span>

Trying with the_field instead of get_field

<span class="c_f"><a href="<?php the_field('field2_link'); ?>"><?php the_field('field1_details'); ?></a></span>


<span><a href="&lt;a href=" http:="" google.com"="" target="_blank">google.com</a>"&gt;This is the test content</span>


The two custom fields works fine if I use them separately like this:

Field 1- field1_details

Output HTML-

<div class="field-wrap"><span class="field icon-edit">This is the Text

Field 2- field2_link

or without the if

<span class="link-field"><?php the_field('field2_link'); ?></span>

Out put-

 <span class="link-field"><a href="http://google.com"

I think I am not using it in a right way. Could any one tell me how to link the field with a URL entered in the another field in loop.php?

Also tell me how would you do it in the functions.php instead of the templates like loop.php

  • Why have you included the if clause? Jan 24, 2014 at 5:32
  • if( function_exists('the_field') ) checks if the ACF function exists.
    – Netizen
    Jan 24, 2014 at 5:36
  • I'm still unsure why you would check (and not check get_field), but you seem to have some syntax problems. Shouldn't it be if( function_exists('the_field') ) {the_field('field1_details')} ? Jan 24, 2014 at 5:41
  • I have tried with out the if. But no change.
    – Netizen
    Jan 24, 2014 at 5:58
  • What is it showing? Can you isolate to see if the problem is the field2_link or the field1_details function? Jan 24, 2014 at 6:05

2 Answers 2


I think your URL is blank because you are simply not printing the result. You can either store the URL in a variable and echo it later:

<?php $myURL = get_field('field2_link'); ?>
<a href="<?php echo $myURL; ?>">

or echo it directly:

<a href="<?php ECHO get_field('field2_link'); ?>">

Either way you need to use the echo "function" to print the results.


According to the documentation, you should display a field like:

<p><?php the_field('field_name'); ?></p>

Change your get_field to the_field:

<span class="c_f"><a href="<?php the_field('field2_link'); ?>"><?php the_field('field1_details'); ?></a></span>
  • I have already tried the_field. But the link is broken. <?php the_field('field_name'); ?> is used to publish the field as it is. I don't know how to make it work to link one field with the other field with Website URL.
    – Netizen
    Jan 24, 2014 at 5:56
  • I don't think I understand what you are trying to do. Is field2_link something like a text field saying google.com? Jan 24, 2014 at 6:01
  • The link field is created using a ACF [addon] (github.com/Jeradin/acf-website-field). The fields created using the addon works fine if I just publish it as <?php the_field('field2_link'); ?> and the other field <?php the_field('field1_details'); ?> separately.
    – Netizen
    Jan 24, 2014 at 6:10
  • field2_link has multiple inputs. What do you see when you display <?php the_field('field2_link'); ?> Jan 24, 2014 at 6:17
  • I have updated the question with output for each of my attempt.
    – Netizen
    Jan 24, 2014 at 7:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.