Using WordPress ‘get_links_list()’ PHP function

The get_links_list() WordPress PHP function outputs a list of all links, listed by category, using the settings in $wpdb->linkcategories and outputs it as a nested HTML unordered list.

Usage

get_links_list($order);

Example:

Input:

get_links_list('name');

Output:

<ul>
  <li><a href="https://example1.com">Example 1</a></li>
  <li><a href="https://example2.com">Example 2</a></li>
  ...
</ul>

Parameters

  • $order (string) Optional: Sort link categories by ‘name’ or ‘id’. Default: ‘name’

More information

See WordPress Developer Resources: get_links_list

Examples

This code snippet will output links sorted by their name in alphabetical order.

get_links_list('name');

This code snippet will output links sorted by their ID.

get_links_list('id');

To display links in a custom HTML structure, you can use wp_list_bookmarks() instead. This example outputs links in a custom HTML structure.

$args = array(
  'title_li' => '',
  'categorize' => 0
);
wp_list_bookmarks($args);

To display links from a specific category, you can use wp_list_bookmarks() with the category parameter. This example displays links from the category with an ID of 3.

$args = array(
  'category' => 3
);
wp_list_bookmarks($args);

To display links with custom formatting, you can use wp_list_bookmarks() with the before and after parameters. This example wraps each link in a custom HTML structure.

$args = array(
  'before' => '<div class="custom-link">',
  'after' => '</div>'
);
wp_list_bookmarks($args);