Home WordPress Bookmark Functions get_bookmarks() WordPress get_bookmarks() Function 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.
get_bookmarks();
get_bookmarks( array( 'orderby' => 'name', 'order' => 'ASC' ) );
get_bookmarks( array( 'category_name' => 'Friends', 'limit' => 5 ) ); Call What 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 get_bookmarks( string|array $args = '' ): object[] Parameters Parameter Description 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 Value Description array of objects One object per bookmark. Each object has fields like link_id, link_name, and link_url. empty array No bookmark matches your arguments.
WordPress Examples Three short theme examples. Each one has a sample output.
1. List all links 2. One category 3. Random links Example 1 — List all links Loop over all visible bookmarks and print each name.
<?php
$links = get_bookmarks();
foreach ( $links as $link ) {
echo esc_html( $link->link_name ) . "\n";
}
?> CodeToFun
Google Developers
WordPress.org How It Works get_bookmarks() returns an array of link objects.foreach visits each link one by one.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.
<?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";
}
?> <a href="https://example.org">Zen Blog</a>
<a href="https://example.com">Alpha Blog</a> How It Works category_name picks one link category.order => DESC sorts from Z to A.Each link becomes an HTML anchor. Example 3 — Show a few random links Pick three random links. Output changes on each page load.
<?php
$links = get_bookmarks( array(
'orderby' => 'rand',
'limit' => 3,
) );
foreach ( $links as $link ) {
echo esc_html( $link->link_name ) . "\n";
}
?> WordPress.org
CodeToFun
Google Developers How It Works orderby => rand shuffles the links.limit => 3 keeps only three of them.Your output will be different each time. Frequently Asked Questions What does get_bookmarks() return? 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.
How do I show links from one category? Pass category_name or category. For example, get_bookmarks( array( 'category_name' => 'Friends' ) ). The category argument takes link category IDs.
Why are some links missing from the result? By default hide_invisible is 1, so links marked as not visible are skipped. Set hide_invisible to 0 to include them.
What is the difference between get_bookmarks() and wp_list_bookmarks()? get_bookmarks() returns data for you to loop over. wp_list_bookmarks() builds and prints the HTML list for you.
How can I show only a few links? Use the limit argument, for example 'limit' => 5. Combine it with orderby to control which links you get.
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.
9 people found this page helpful
Helpful Share Copy link Suggestion