WordPress get_bookmarks() Function

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

Definition

In WordPress, get_bookmarks() returns a list of bookmarks (links). Each item is an object with fields such as link_name and link_url.

It returns an array. You loop over it with foreach and print what you need. To print a ready-made HTML list, use wp_list_bookmarks().

Syntax

Pass an array of arguments to sort and filter the links.

WordPress
get_bookmarks();
get_bookmarks( array( 'orderby' => 'name', 'order' => 'ASC' ) );
get_bookmarks( array( 'category_name' => 'Friends', 'limit' => 5 ) );
CallWhat it does
get_bookmarks()Returns all visible bookmarks, sorted by name.
get_bookmarks( array( 'orderby' => 'name' ) )Sorts the links by the field you choose.
get_bookmarks( array( 'category_name' => 'Friends' ) )Returns only links from one link category.

The result is an array. It is empty when no link matches.

Full declaration
WordPress
get_bookmarks( string|array $args = '' ): object[]

Parameters

ParameterDescription
orderbySort field: name (default), url, id, rating, rand, and more.
orderASC (default) or DESC.
limitMaximum number of links. Default is -1 (no limit).
categoryComma-separated link category IDs.
category_nameThe name of one link category.
hide_invisibleHide links marked as not visible. Default is 1.
include / excludeComma-separated link IDs to include or leave out.
searchReturn links that match this text in the name, URL, or description.

You can pass the arguments as an array or as a query string such as 'orderby=name&limit=5'.

Return Value

Return ValueDescription
array of objectsOne object per bookmark. Each object has fields like link_id, link_name, and link_url.
empty arrayNo bookmark matches your arguments.

WordPress Examples

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

Example 1 — List all links

Loop over all visible bookmarks and print each name.

WordPress
<?php
$links = get_bookmarks();

foreach ( $links as $link ) {
  echo esc_html( $link->link_name ) . "\n";
}
?>

How It Works

  1. get_bookmarks() returns an array of link objects.
  2. foreach visits each link one by one.
  3. Links are sorted by name because that is the default.

Example 2 — One link category, sorted

Show only links from the Friends category, in Z to A order.

WordPress
<?php
$links = get_bookmarks( array(
  'category_name' => 'Friends',
  'orderby'       => 'name',
  'order'         => 'DESC',
) );

foreach ( $links as $link ) {
  echo '<a href="' . esc_url( $link->link_url ) . '">'
     . esc_html( $link->link_name ) . "</a>\n";
}
?>

How It Works

  1. category_name picks one link category.
  2. order => DESC sorts from Z to A.
  3. Each link becomes an HTML anchor.

Example 3 — Show a few random links

Pick three random links. Output changes on each page load.

WordPress
<?php
$links = get_bookmarks( array(
  'orderby' => 'rand',
  'limit'   => 3,
) );

foreach ( $links as $link ) {
  echo esc_html( $link->link_name ) . "\n";
}
?>

How It Works

  1. orderby => rand shuffles the links.
  2. limit => 3 keeps only three of them.
  3. Your output will be different each time.

Frequently Asked Questions

It returns an array of bookmark objects. Each object has fields such as link_id, link_name, link_url, and link_description. The array is empty when nothing matches.
Pass category_name or category. For example, get_bookmarks( array( 'category_name' => 'Friends' ) ). The category argument takes link category IDs.
By default hide_invisible is 1, so links marked as not visible are skipped. Set hide_invisible to 0 to include them.
get_bookmarks() returns data for you to loop over. wp_list_bookmarks() builds and prints the HTML list for you.
Use the limit argument, for example 'limit' => 5. Combine it with orderby to control which links you get.

Next: wp_list_bookmarks()

Print a ready-made HTML list of bookmarks.

wp_list_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.

9 people found this page helpful