WpCode.net

Daily Wordpress Code Snippet

How to add a Bookmark to admin menu

| 0 comments

Pin It

This cool snippet will add a bookmark button to default wordpress admin bar, so you can browse between the bar specific posts. in the $cat variable you must specific a category id, where you will publish the bookmark.

Add this code to your wordpress function.php file Continue reading

add_filter('wp_nav_menu_items', 'add_bookmarks', 10, 2);
function add_bookmarks($items, $args) {
	$cat = '2'; // define category
	$bookmarks = array();
	$bookmarks = get_bookmarks("category=$cat");
	if ($bookmarks[0] != '') {
	    $items .= '<li><a href="#">Bookmarks</a><ul class="sub-menu">';
	    foreach ( $bookmarks as $bookmark ) {
		$items .= '<li><a href="'.clean_url($bookmark->link_url).'">'.$bookmark->link_name.'</a></li>';
	    }
	    $items .= '</ul>';
	  }
	return $items;
}

Leave a Reply

Required fields are marked *.

*