Black Friday 50% OFF! Coupon “BLACKFRIDAY50” Ends in:

0

Days

:

0

Hrs

:

0

Mins

:

0

Secs

Shop now!
WPLake > Learning Hub > ACF Link Fields: Url, Link, and Page Link

ACF Link Fields: Url, Link, and Page Link

Discover link field types in ACF: Url, Link, and Page Link. Understand storage, internal vs. external linking, and simplification with Smart Templates.

Key Points at a Glance

  1. Link Types Overview: ACF offers the Url, Link, and Page Link field types for adding links to pages and websites within WordPress, each with distinct categorizations and behaviors.
  2. External vs. Internal Linking: Url and Link fields support both internal and external links, while Page Link restricts selection to internal pages, offering filtering options for precise link selection within the website.
  3. Data Storage: Each field type stores values differently, with Url as a string, Link as an array, and Page Link as an object ID.
  4. Query and Display Simplification: Smart Templates from plugins like Advanced Views streamline query and display tasks by handling field formats and conversions, allowing focus on layout design.

Table of Contents

About ACF Url, Link, and Page Link fields

Advanced Custom Fields (ACF) stands out as one of the best meta field plugins available. The Url, Link, and Page Link field types all share a common purpose: enabling editors to add links to other pages and websites within the current object.

However, ACF categorizes them into different field groups: Url belongs to the Basic group, while Link and Page Link are in the Relational group. This categorization indicates that while they serve a similar purpose, each has its own distinct behavior.

This article will walk you through the main differences among them, helping you determine which field type best suits your specific case. Let's have a look on their field settings:

ACF Url field
URL field settings are brief and consist solely of the default items
ACF Link field
The Link field includes the Return Value setting.
ACF Page Link field
The Page Link field is the most advanced, incorporating a row of filters and allowing for the enabling of the multiple-choice option.

Now let's see what the field inputs look like for editors.

ACF Link fields look for editors
Editor's appearance for Link field inputs

The Url and Page Link field values have classic on-page inputs, while the Link field value is managed via the native WordPress popup:

ACF Link field uses the WordPress link popup
The native WordPress link popup enables editors to manage all link settings and easily locate existing pages by their names

We've evaluated the appearance and UX of the fields. Now, let's delve into their key differences. This will provide you with a clearer understanding of each field, aiding you in selecting the most suitable one for your specific use case.

1. External vs Internal targets within the Link fields

The primary distinction among link-related field types lies in the target types of the links they support.

Note: "Internal" links refer to links that direct users to pages within the current website, while "External" links point to pages on other websites.

The Url and Link field types are text-based fields, enabling editors to insert both internal and external links. On the other hand, the Page Link field is a select-based field that allows editors to choose from pages within the current website only.

Given that the Page Link field settings enable filtering of available options by post type, post status, and taxonomy, this field type is ideal for scenarios where we need to restrict link selection within the current website and ensure precision.

The Link field stands out as the most versatile option, allowing users to choose from existing pages or define a custom link. Additionally, it includes a 'link text' setting, empowering editors to control the link title.

Meanwhile, the URL field serves as a straightforward text input, primarily used for external links. It lacks the ability to control the link label, making it most suitable for cases where simplicity is key.

To provide clarity, we've created a brief comparison table below:

Field typeLink typePage search option
UrlInternal and Externalno
LinkInternal and Externalyes
Page linkInternal onlyyes, plus extra filters

Pro tip for internal links: While the Page Link field permits the definition of post type and taxonomy filters, these settings are configured at the field level, which means editors do not have direct access to these filters. By utilizing the Relationship field, you can grant editors access to these filters, enhancing flexibility and customization options.

2. Detailed vs Short data inside the Link fields

The next notable distinction lies in the customization options provided by each field type. These options determine the format of the value saved in the database, as well as the ways by which we can utilize it.

Field typeCustomizable link settings (title/blank)Stored DB value
Urlnostring (URL)
Linkyesarray (URL, label, isBlank setting)
Page linknoint (post id)

As depicted in the comparison table above, each field type stores the chosen value in its unique format.

The URL field stores it as a string, the Link field as an array representing chosen options, while the Page Link field stores the ID of the chosen object.

This determines the information we can extract from the saved value. While the Link field's value appears promising, it's essential not to mistake its array format.

In fact, the Page Link field stores the most comprehensive value, as using the object ID allows us to retrieve any information about the page, including title, author, category, and more.

The additional advantage of the Page Link value format is that it isn't tightly bound to the current page URL. If you later modify it or migrate from a development to a live domain, you won't need to execute a replace command for this field.

Taking all of the aforementioned into account, it's reasonable to conclude that the Page Link field is the optimal choice for internal links, whereas the Link field is preferable for external or mixed cases.

The URL field can still be utilized in scenarios where you want to provide the simplest input UI for editors.

Tip: The Url field's hidden strength lies in its ease of participation in Meta Queries. Constructing Meta queries with this field is straightforward due to its saved format. You can effortlessly query all pages where the URL field mentions a specific domain using the 'Like' comparison. This can be achieved using the WP_Query class or the Advanced Views framework.

3. Return Format of the Link fields

Since we've covered all the main field features, let's review their Return Value Formats.

While it's necessary to consider the return formats when displaying the field value, keep in mind that this setting doesn't affect the format used for saving data in the database. The Return Format setting only affects the value retrieved from the ACF get_field function.

So, let's examine the responses we'll receive when calling the get_field function for different types of link fields:

Url field: return format

Always URL as a string.

Link field: return formats

Depending on the Return Format setting:

a) an Array, with the following keys: 'url' (string), 'title' (string), and 'target' (bool, optional)

b) URL as a string

Page link field: return formats

Depending on the 'Multiple' setting:

a) an object ID (integer)

b) an array of object IDs

Utilizing this knowledge, we can extract the value of any link field and integrate it into our markup.

Tip: While having multiple options and return formats offers flexibility, it can also complicate the display task. The Advanced Views framework introduces Smart templates, which handle all field formats and conversions, enabling you to concentrate on the layout itself.

Summary

The Url, Link, and Page Link field types all serve a common purpose: enabling editors to add links to other pages and websites within the current object.

However, despite their shared purpose, each type exhibits distinct behavior.

The primary difference among these field types lies in the target types of the links they support.

Url and Link fields are text-based, allowing editors to insert both internal and external links. In contrast, the Page Link field is select-based, restricting editors to choosing from pages within the current website only.

Given that Page Link field settings enable filtering of available options by post type, post status, and taxonomy, this field type is ideal for scenarios where we need to restrict link selection within the current website and ensure precision.

The Link field stands out as the most versatile option, offering users the choice between existing pages or defining a custom link. Additionally, it includes a 'link text' setting, empowering editors to control the link title.

The value returned by the ACF get_field() function call depends on the field settings and may include a string, array, or ID. To simplify query and display tasks, we can utilize Smart Templates from the Advanced Views framework.

Stuck with development or facing an issue?

WPLake offers affordable on-demand website development and design.

No matter the size of your project - contact us now, and we'll get it done for you!

Get assistance now

FAQ mode

/

Learning mode

  1. What are the return value formats for each field type?

    The Url field returns a string, the Link field returns an array or string, depending on settings, and the Page Link field returns an object ID or array.

Was this article helpful?

Totally useless

Slightly helpful

Very helpful

Related articles

Content links (14)

About the Author

Maxim Akimov

Certified WordPress expert from Ukraine with over 8 years of experience. Advocate of the BEM methodology and the overall modular approach. Loves sporting activities and enjoys going to the gym and regularly plays table tennis.

0 Comments

    Leave a comment

    Reply to 

    Please be considerate when leaving a comment.

    Not shown publicly


    Got it