WordPress get_bookmark_field() Function

Beginner
4 min read
Updated: Nov 2026
3 examples
Returns a field

Definition

In WordPress, get_bookmark_field() returns one field of a bookmark. For example, you can get the link name, the URL, or the description.

You give it the field name and the link ID. It returns the value as a string. It does not print it.

Syntax

Pass the field name first, then the link ID.

WordPress
get_bookmark_field( 'link_name', 2 );
get_bookmark_field( 'link_url', 2 );
get_bookmark_field( 'link_description', 2, 'display' );
CallWhat it does
get_bookmark_field( 'link_name', 2 )Returns the name of link 2.
get_bookmark_field( 'link_url', 2 )Returns the web address of link 2.
get_bookmark_field( 'link_description', 2, 'display' )Returns the description prepared for display.

It returns an empty string when the link or the field is missing.

Full declaration
WordPress
get_bookmark_field( string $field, int $bookmark, string $context = 'display' ): string|WP_Error

Parameters

ParameterDescription
$fieldRequired. The field name, such as link_name, link_url, or link_description.
$bookmarkRequired. The link ID.
$contextOptional. How to prepare the value. Default is 'display'. Use 'raw' for the stored value.

Common fields: link_id, link_url, link_name, link_description, link_visible, link_rating, link_rel, link_target, link_image, link_notes, link_owner, link_updated, link_category.

Return Value

Return ValueDescription
stringThe value of the field.
empty stringThe link or the field was not found.
WP_ErrorAn error object. Check with is_wp_error().

WordPress Examples

Three short theme examples. Each one has a sample output.

Example 1 — Get the link name

Print the name of one bookmark.

WordPress
<?php
echo esc_html( get_bookmark_field( 'link_name', 2 ) );
?>

How It Works

  1. link_name is the field you want.
  2. 2 is the link ID.
  3. esc_html() keeps the output safe.

Example 2 — Make a link from the URL

Get the URL and use it in an HTML link.

WordPress
<?php
$url = get_bookmark_field( 'link_url', 2 );

if ( $url ) {
  echo '<a href="' . esc_url( $url ) . '">Visit site</a>';
}
?>

How It Works

  1. The URL is saved in $url.
  2. The if check skips empty values.
  3. esc_url() cleans the web address.

Example 3 — Check for an empty value

Handle a missing field or an error before you print.

WordPress
<?php
$desc = get_bookmark_field( 'link_description', 2 );

if ( is_wp_error( $desc ) || '' === $desc ) {
  echo 'No description.';
} else {
  echo esc_html( $desc );
}
?>

How It Works

  1. is_wp_error() checks for an error object.
  2. An empty string means there is nothing to show.
  3. Otherwise the description is printed safely.

Frequently Asked Questions

It returns one field of a bookmark as a string. If the link or the field does not exist, it returns an empty string. It can also return a WP_Error object.
Use the column names of a link, such as link_id, link_url, link_name, link_description, link_visible, link_rating, link_rel, link_target, link_image, link_notes, link_owner, link_updated, and link_category.
It tells WordPress how to prepare the value. The default is 'display'. Use 'raw' when you want the value as it is stored.
Use get_bookmark() when you need many fields of the same link. Use get_bookmark_field() when you only need one value.
Yes. Use esc_html() for text, esc_url() for URLs, and esc_attr() for attributes.

Next: get_bookmarks()

Get a whole list of bookmarks and loop over them.

get_bookmarks() tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

7 people found this page helpful