WordPress get_bookmark() Function

Beginner
4 min read
Updated: Nov 2026
3 examples
Returns data

Definition

In WordPress, get_bookmark() gets one bookmark from your Links list. You pass the link ID. WordPress returns the link data.

A bookmark is a saved link in the classic Links Manager (the wp_links table). It returns the data. It does not print anything.

Syntax

Pass the link ID. You can also choose the return type.

WordPress
get_bookmark( 2 );
get_bookmark( 2, ARRAY_A );
get_bookmark( 2, OBJECT, 'display' );
CallWhat it does
get_bookmark( 2 )Returns the link as an object.
get_bookmark( 2, ARRAY_A )Returns the link as an array with named keys.
get_bookmark( 2, OBJECT, 'display' )Returns an object with values prepared for display.

Always check that the result is not null before you use it.

Full declaration
WordPress
get_bookmark( int|stdClass $bookmark, string $output = OBJECT, string $filter = 'raw' ): array|object|null

Parameters

ParameterDescription
$bookmarkRequired. The link ID (or a link object).
$outputOptional. OBJECT (default), ARRAY_A (named keys), or ARRAY_N (numbers).
$filterOptional. How to prepare the values. Default is 'raw'. Use 'display' when you print them.

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
objectThe bookmark as an object. Default when $output is OBJECT.
arrayThe bookmark as an array when you use ARRAY_A or ARRAY_N.
nullNo bookmark was found for that ID.

WordPress Examples

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

Example 1 — Name and URL

Get one link by ID and print its name and URL.

WordPress
<?php
$link = get_bookmark( 2 );

if ( $link ) {
  echo esc_html( $link->link_name ) . ' - ' . esc_url( $link->link_url );
}
?>

How It Works

  1. get_bookmark( 2 ) returns the link with ID 2.
  2. The if check skips the code when the link is missing.
  3. Fields are read as object properties, such as $link->link_name.

Example 2 — Return an array

Use ARRAY_A to read fields by key.

WordPress
<?php
$link = get_bookmark( 2, ARRAY_A );

if ( $link ) {
  echo esc_html( $link['link_name'] ) . "\n";
  echo esc_html( $link['link_description'] );
}
?>

How It Works

  1. ARRAY_A gives an array with named keys.
  2. Use $link['link_name'] instead of an arrow.
  3. esc_html() keeps the text safe.

Example 3 — Build a clickable link

Use the saved URL, name, and target to make an HTML link.

WordPress
<?php
$link = get_bookmark( 2 );

if ( $link ) {
  printf(
    '<a href="%s" target="%s">%s</a>',
    esc_url( $link->link_url ),
    esc_attr( $link->link_target ),
    esc_html( $link->link_name )
  );
}
?>

How It Works

  1. link_url is the web address.
  2. link_target can be _blank or empty.
  3. printf() puts each safe value into the HTML.

Frequently Asked Questions

It returns one bookmark (link) as an object by default. You can ask for an array with ARRAY_A or ARRAY_N. If the link does not exist, it returns null.
A bookmark is a saved link in the classic Links feature of WordPress. It has a name, a URL, a description, and a link category. It is also called a blogroll link.
Open the Links screen in your admin area and hover over a link. The URL contains link_id=. If the Links menu is missing, install the Link Manager plugin.
get_bookmark() returns one link by ID. get_bookmarks() returns a list of many links, and you can filter and sort them.
Yes. Use esc_html() for text, esc_url() for URLs, and esc_attr() for attributes when you print the fields.

Next: get_bookmark_field()

Get just one field of a bookmark, such as its name or URL.

get_bookmark_field() 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.

8 people found this page helpful