Home WordPress Bookmark Functions get_bookmark() WordPress get_bookmark() Function 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.
get_bookmark( 2 );
get_bookmark( 2, ARRAY_A );
get_bookmark( 2, OBJECT, 'display' ); Call What 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 get_bookmark( int|stdClass $bookmark, string $output = OBJECT, string $filter = 'raw' ): array|object|null Parameters Parameter Description $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 Value Description object The bookmark as an object. Default when $output is OBJECT. array The bookmark as an array when you use ARRAY_A or ARRAY_N. null No bookmark was found for that ID.
WordPress Examples Three short theme examples. Each one has a sample output.
1. Name and URL 2. Return an array 3. Build a link Example 1 — Name and URL Get one link by ID and print its name and URL.
<?php
$link = get_bookmark( 2 );
if ( $link ) {
echo esc_html( $link->link_name ) . ' - ' . esc_url( $link->link_url );
}
?> CodeToFun - https://www.codetofun.com How It Works get_bookmark( 2 ) returns the link with ID 2.The if check skips the code when the link is missing. Fields are read as object properties, such as $link->link_name. Example 2 — Return an array Use ARRAY_A to read fields by key.
<?php
$link = get_bookmark( 2, ARRAY_A );
if ( $link ) {
echo esc_html( $link['link_name'] ) . "\n";
echo esc_html( $link['link_description'] );
}
?> CodeToFun
Free tutorials for web developers. How It Works ARRAY_A gives an array with named keys.Use $link['link_name'] instead of an arrow. esc_html() keeps the text safe.Example 3 — Build a clickable link Use the saved URL, name, and target to make an HTML link.
<?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 )
);
}
?> <a href="https://www.codetofun.com" target="_blank">CodeToFun</a> How It Works link_url is the web address.link_target can be _blank or empty.printf() puts each safe value into the HTML.Frequently Asked Questions What does get_bookmark() return? 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.
What is a WordPress bookmark? 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.
How do I find the bookmark ID? 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.
What is the difference between get_bookmark() and get_bookmarks()? get_bookmark() returns one link by ID. get_bookmarks() returns a list of many links, and you can filter and sort them.
Should I escape the values? Yes. Use esc_html() for text, esc_url() for URLs, and esc_attr() for attributes when you print the fields.
About the author Developer, cloud engineer, and technical writer
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
Helpful Share Copy link Suggestion