Add Favorite Button To WordPress Gallery & Attachment Images


This code adds a favorite button to gallery & attachment page images in the Twenty Twenty default theme for WordPress.

How To Favorite Photo

The code adds the favorites button to :

  • All galleries you create using the native WordPress gallery.
  • All attachment page gallery images which display the individual images in the gallery.

Works in any WordPress theme.


This system :

  1. Allows users to subscribe and create their own username & password which gives them access to their own dashboard.
  2. Enables you to create unlimited photo galleries in grid format with any number of columns and size of image.
  3. Enables users to quickly browse thumbnail images which once clicked, open a larger image on a separate page with the ability to add captions, image descriptions and photo credits.
  4. Enables users to favorite, like or love individual photos. Each gallery includes a comment form where users can submit questions and feedback about specific photos or entire galleries of images.
  5. Includes analytics showing how many times each photo has been liked, loved or favorited.


There’s 4 steps :

Step 1 – Install the Favorites plugin and configure the settings as seen in this image.

Step 2 – Copy & paste the PHP code from the functions.php file to your child themes functions file or custom functionality plugin.

Step 3 – Upload the attachment.php template file and templates-parts folder to your child theme folder.

Step 4 – Copy & paste the CSS to the end of your stylesheet and remember to clear caching.

Related Tutorials

You may also like…