Title: get_bookmark
Published: April 25, 2014
Last modified: February 24, 2026

---

# get_bookmark( int|stdClass $bookmark, string $output = OBJECT, string $filter ): array|object|null

## In this article

 * [Parameters](https://developer.wordpress.org/reference/functions/get_bookmark/?output_format=md#parameters)
 * [Return](https://developer.wordpress.org/reference/functions/get_bookmark/?output_format=md#return)
 * [Source](https://developer.wordpress.org/reference/functions/get_bookmark/?output_format=md#source)
 * [Related](https://developer.wordpress.org/reference/functions/get_bookmark/?output_format=md#related)
 * [Changelog](https://developer.wordpress.org/reference/functions/get_bookmark/?output_format=md#changelog)
 * [User Contributed Notes](https://developer.wordpress.org/reference/functions/get_bookmark/?output_format=md#user-contributed-notes)

[ Back to top](https://developer.wordpress.org/reference/functions/get_bookmark/?output_format=md#wp--skip-link--target)

Retrieves bookmark data.

## 󠀁[Parameters](https://developer.wordpress.org/reference/functions/get_bookmark/?output_format=md#parameters)󠁿

 `$bookmark`int|stdClassrequired

`$output`stringoptional

The required return type. One of OBJECT, ARRAY_A, or ARRAY_N, which correspond to
an stdClass object, an associative array, or a numeric array, respectively.

Default:`OBJECT`

`$filter`stringoptional

How to sanitize bookmark fields. Default `'raw'`.

## 󠀁[Return](https://developer.wordpress.org/reference/functions/get_bookmark/?output_format=md#return)󠁿

 array|object|null Type returned depends on $output value.

## 󠀁[Source](https://developer.wordpress.org/reference/functions/get_bookmark/?output_format=md#source)󠁿

    ```php
    function get_bookmark( $bookmark, $output = OBJECT, $filter = 'raw' ) {
    	global $wpdb;

    	if ( empty( $bookmark ) ) {
    		if ( isset( $GLOBALS['link'] ) ) {
    			$_bookmark = & $GLOBALS['link'];
    		} else {
    			$_bookmark = null;
    		}
    	} elseif ( is_object( $bookmark ) ) {
    		wp_cache_add( $bookmark->link_id, $bookmark, 'bookmark' );
    		$_bookmark = $bookmark;
    	} else {
    		if ( isset( $GLOBALS['link'] ) && ( $GLOBALS['link']->link_id === $bookmark ) ) {
    			$_bookmark = & $GLOBALS['link'];
    		} else {
    			$_bookmark = wp_cache_get( $bookmark, 'bookmark' );
    			if ( ! $_bookmark ) {
    				$_bookmark = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $wpdb->links WHERE link_id = %d LIMIT 1", $bookmark ) );
    				if ( $_bookmark ) {
    					$_bookmark->link_category = array_unique( wp_get_object_terms( $_bookmark->link_id, 'link_category', array( 'fields' => 'ids' ) ) );
    					wp_cache_add( $_bookmark->link_id, $_bookmark, 'bookmark' );
    				}
    			}
    		}
    	}

    	if ( ! $_bookmark ) {
    		return $_bookmark;
    	}

    	$_bookmark = sanitize_bookmark( $_bookmark, $filter );

    	if ( OBJECT === $output ) {
    		return $_bookmark;
    	} elseif ( ARRAY_A === $output ) {
    		return get_object_vars( $_bookmark );
    	} elseif ( ARRAY_N === $output ) {
    		return array_values( get_object_vars( $_bookmark ) );
    	} else {
    		return $_bookmark;
    	}
    }
    ```

[View all references](https://developer.wordpress.org/reference/files/wp-includes/bookmark.php/)
[View on Trac](https://core.trac.wordpress.org/browser/tags/6.9.4/src/wp-includes/bookmark.php#L24)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/6.9.4/src/wp-includes/bookmark.php#L24-L66)

## 󠀁[Related](https://developer.wordpress.org/reference/functions/get_bookmark/?output_format=md#related)󠁿

| Uses | Description | 
| [wp_cache_add()](https://developer.wordpress.org/reference/functions/wp_cache_add/)`wp-includes/cache.php` |

Adds data to the cache, if the cache key doesn’t already exist.

  | 
| [wp_get_object_terms()](https://developer.wordpress.org/reference/functions/wp_get_object_terms/)`wp-includes/taxonomy.php` |

Retrieves the terms associated with the given object(s), in the supplied taxonomies.

  | 
| [sanitize_bookmark()](https://developer.wordpress.org/reference/functions/sanitize_bookmark/)`wp-includes/bookmark.php` |

Sanitizes all bookmark fields.

  | 
| [wpdb::get_row()](https://developer.wordpress.org/reference/classes/wpdb/get_row/)`wp-includes/class-wpdb.php` |

Retrieves one row from the database.

  | 
| [wp_cache_get()](https://developer.wordpress.org/reference/functions/wp_cache_get/)`wp-includes/cache.php` |

Retrieves the cache contents from the cache by key and group.

  | 
| [wpdb::prepare()](https://developer.wordpress.org/reference/classes/wpdb/prepare/)`wp-includes/class-wpdb.php` |

Prepares a SQL query for safe execution.

  |

[Show 2 more](https://developer.wordpress.org/reference/functions/get_bookmark/?output_format=md#)
[Show less](https://developer.wordpress.org/reference/functions/get_bookmark/?output_format=md#)

| Used by | Description | 
| [wp_ajax_delete_link()](https://developer.wordpress.org/reference/functions/wp_ajax_delete_link/)`wp-admin/includes/ajax-actions.php` |

Handles deleting a link via AJAX.

  | 
| [get_link_to_edit()](https://developer.wordpress.org/reference/functions/get_link_to_edit/)`wp-admin/includes/bookmark.php` |

Retrieves link data based on its ID.

  | 
| [wp_update_link()](https://developer.wordpress.org/reference/functions/wp_update_link/)`wp-admin/includes/bookmark.php` |

Updates a link in the database.

  | 
| [get_link()](https://developer.wordpress.org/reference/functions/get_link/)`wp-includes/deprecated.php` |

Retrieves bookmark data based on ID.

  | 
| [get_edit_bookmark_link()](https://developer.wordpress.org/reference/functions/get_edit_bookmark_link/)`wp-includes/link-template.php` |

Displays the edit bookmark link.

  | 
| [edit_bookmark_link()](https://developer.wordpress.org/reference/functions/edit_bookmark_link/)`wp-includes/link-template.php` |

Displays the edit bookmark link anchor content.

  | 
| [get_bookmark_field()](https://developer.wordpress.org/reference/functions/get_bookmark_field/)`wp-includes/bookmark.php` |

Retrieves single bookmark data item or field.

  |

[Show 2 more](https://developer.wordpress.org/reference/functions/get_bookmark/?output_format=md#)
[Show less](https://developer.wordpress.org/reference/functions/get_bookmark/?output_format=md#)

## 󠀁[Changelog](https://developer.wordpress.org/reference/functions/get_bookmark/?output_format=md#changelog)󠁿

| Version | Description | 
| [2.1.0](https://developer.wordpress.org/reference/since/2.1.0/) | Introduced. |

## 󠀁[User Contributed Notes](https://developer.wordpress.org/reference/functions/get_bookmark/?output_format=md#user-contributed-notes)󠁿

 1.   [Skip to note 3 content](https://developer.wordpress.org/reference/functions/get_bookmark/?output_format=md#comment-content-1447)
 2.    [Codex](https://profiles.wordpress.org/codex/)  [  10 years ago  ](https://developer.wordpress.org/reference/functions/get_bookmark/#comment-1447)
 3.  [You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fget_bookmark%2F%23comment-1447)
     Vote results for this note: 0[You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fget_bookmark%2F%23comment-1447)
 4.  **Display Bookmark Name**
 5.      ```php
         <?php 
         $bookmark = get_bookmark(5);
         echo $bookmark->link_name; 
         ?>
         ```
     
 6.  or:
 7.      ```php
         <?php echo get_bookmark(5)->link_name; ?>
         ```
     
 8.   [Log in to add feedback](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fget_bookmark%2F%3Freplytocom%3D1447%23feedback-editor-1447)
 9.   [Skip to note 4 content](https://developer.wordpress.org/reference/functions/get_bookmark/?output_format=md#comment-content-1448)
 10.   [Codex](https://profiles.wordpress.org/codex/)  [  10 years ago  ](https://developer.wordpress.org/reference/functions/get_bookmark/#comment-1448)
 11. [You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fget_bookmark%2F%23comment-1448)
     Vote results for this note: 0[You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fget_bookmark%2F%23comment-1448)
 12. **Display Bookmark as a Link**
 13.     ```php
         <?php  
         $bookmark = get_bookmark(5);
         echo '<a href="'.$bookmark->link_url.'">'.$bookmark->link_name.'</a>';
         ?>
         ```
     
 14.  [Log in to add feedback](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fget_bookmark%2F%3Freplytocom%3D1448%23feedback-editor-1448)

You must [log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fget_bookmark%2F)
before being able to contribute a note or feedback.