Using WordPress ‘get_link()’ PHP function

The get_link() WordPress PHP function retrieves bookmark data based on its ID.

Usage

get_link( $bookmark_id, $output, $filter )

Custom Example:

Input:

$bookmark_id = 1;
$output = OBJECT;
$filter = 'raw';
$bookmark = get_link( $bookmark_id, $output, $filter );

Output:
A bookmark object with raw data.

Parameters

  • $bookmark_id (int) – The ID of the link.
  • $output (string) – Optional. Type of output. Accepts OBJECT, ARRAY_N, or ARRAY_A. Default: OBJECT.
  • $filter (string) – Optional. How to filter the link for output. Accepts ‘raw’, ‘edit’, ‘attribute’, ‘js’, ‘db’, or ‘display’. Default ‘raw’.

More information

See WordPress Developer Resources: get_link()

Examples

Retrieve a Bookmark Object

This example retrieves a bookmark object with the default output type (OBJECT) and filter (‘raw’).

$bookmark_id = 1;
$bookmark = get_link( $bookmark_id );

Retrieve a Bookmark as an Array

This example retrieves a bookmark as an associative array with the ‘display’ filter.

$bookmark_id = 1;
$output = ARRAY_A;
$filter = 'display';
$bookmark = get_link( $bookmark_id, $output, $filter );

Retrieve a Bookmark with ‘edit’ Filter

This example retrieves a bookmark object with the ‘edit’ filter.

$bookmark_id = 1;
$filter = 'edit';
$bookmark = get_link( $bookmark_id, OBJECT, $filter );

Display Bookmark Title

This example retrieves a bookmark object and displays its title.

$bookmark_id = 1;
$bookmark = get_link( $bookmark_id );
echo $bookmark->link_name;

Display Bookmark URL

This example retrieves a bookmark object and displays its URL.

$bookmark_id = 1;
$bookmark = get_link( $bookmark_id );
echo $bookmark->link_url;