How to add Favorites feature for your site’s users in Genesis

Posted on Leave a comment
5/5 - (135 votes)

Favorites plugin provides a way to save favorites, likes, bookmarks, or any other similar types of data with customizable button text. In this article we shall add a button in the entry header’s post info on archives and single post pages to favorite posts along with favorite count for logged in members.

Non logged-in visitors will be set to see only the favorite count.

For members we can create a Page that shows the list of posts they have added as favorites and a button to clear the favorites.

While the tutorial has been written for Genesis Sample child theme it should work with minor adjustments in any Genesis child theme.

Step 1

Install and activate Favorites.

In this example since we want to enable Favorites only for logged in users, go to Settings > Favorites and untick “Enable Favorites”.

In the Display tab, enable the post types for which Favorites should be enabled and tick ‘Favorite Count’.

Step 2

Add the following in child theme’s functions.php:

// Customize entry meta in the entry header to show Favorite button for logged in users and Favorites count for non logged in users
add_filter( 'genesis_post_info', 'sk_post_info_filter' );
function sk_post_info_filter( $post_info ) {

	if ( is_user_logged_in() ) {
		$post_info = '[post_date] by [post_author_posts_link] [post_comments] [post_edit] [favorite_button]';
	} else {
		$post_info = '[post_date] by [post_author_posts_link] [post_comments] [post_edit] Favorited: [favorite_count] times';
	}

	return $post_info;
}

Step 3

Add the following in child theme’s style.css and modify to suit:

.entry-meta .simplefavorite-button {
	float: right;
	padding: 0;
	background-color: transparent;
	color: #333;
	text-transform: none;
}

.favorite-count {
	float: right;
}

Step 4

Create a Page titled say, Favorites having the following:

[user_favorites include_links="true" post_types="post" include_buttons="false"]

[clear_favorites_button]

Leave a Reply

Your email address will not be published. Required fields are marked *