Docs    Instagram    Customizations

How to change the color of the icons when a photo has a like or comment

A JavaScript snippet that colours the like and comment icons only when a post has received one.

Would you like to change the color of the like and comment icons only on the posts that have a like or a comment?

Before you get started, Instagram Feed Pro must be installed and activated on your WordPress site.

Requirements: Like and comment counts need the Basic license level or higher, and a feed whose source is connected with Just my posts or My posts and more.

Change the Icon Color for Posts With Likes or Comments

By default, the like and comment icons keep the same color whether a post has 0 likes and comments or more. The Color setting in the feed customizer sets one color for every post. For what that setting does, see our guide on changing the like and comment summary. A small JavaScript snippet can color the icons only when the count is above 0.

The counts come from sources connected with Just my posts or My posts and more (Business Basic or Business Advanced on the old connection page). Since December 4, 2024, Instagram no longer lets Personal accounts use its API. A Personal source needs to reconnect with one of those 2 options. To reconnect, see our guide on reconnecting a Personal source. In the feed customizer, the counts show below each post when Enable is on in Customize » Posts » Like and Comment Summary. They show over a post on hover when Like/Comment Icons is checked in Customize » Posts » Hover State.

The snippet below colors the icons and their numbers in both places, for every Instagram feed on the page. It checks the like and comment counts separately. An icon with a count of 0 keeps its normal color. When the count is above 0, the snippet’s color replaces the colors set in the feed customizer. You can keep the Color setting for the icons with 0.

Next, we’ll add the snippet in WPCode.

Add the Snippet in WPCode

The old Custom JS box in the plugin is deprecated. WPCode replaces it. To see how this works, read our guide on the WPCode integration.

The plugin runs a function named sbi_custom_js after the feed loads and again after you click Load More. WordPress loads jQuery in no-conflict mode. For this reason, the first line inside the function sets $. Add this as a new JavaScript snippet in the site-wide footer in WPCode.

The WPCode code type window with a red box around the JavaScript Snippet option
The WPCode Location menu open, with an arrow pointing to the Site Wide Footer option
var sbi_custom_js = function() {
   var $ = jQuery;
   $('#sb_instagram .sbi_item').each(function(){
      var $self = $(this);
      if( parseInt( $self.find('.sbi_likes').text() ) > 0 ) $self.find('.sbi_likes, .sbi_likes svg').css('color', 'blue');
      if( parseInt( $self.find('.sbi_comments').text() ) > 0 ) $self.find('.sbi_comments, .sbi_comments svg').css('color', 'blue');
   });
};
The WPCode snippet editor with the title field empty and the code above pasted into the Code Preview box, with JavaScript Snippet as the code type

The code above changes the color of the icons and their numbers to blue. To use a different color, replace blue in the two 'color', 'blue' parts with any color name or HEX code, such as #e1306c. Then make the snippet active and save it in WPCode.

The top bar of the WPCode snippet editor with the toggle set to Active and arrows pointing to the toggle and the Save Snippet button

That’s it! Like and comment icons with a count above 0 now show in your color.

If the icons or numbers don’t show at all, check the customizer settings above. If your feed uses a Personal source, see our guide on reconnecting a Personal source.

Frequently Asked Questions

Below, we’ve answered some of the most common questions about coloring the like and comment icons.

Why don’t I see likes and comments on my feed?

The counts show only for feeds whose source is connected with Just my posts or My posts and more. A feed with a Personal source needs to reconnect it with one of those 2 options. Also check that Like and Comment Summary is enabled, or that Like/Comment Icons is checked in Hover State.

Can I use one color for every post instead?

Yes. In the feed customizer, go to Customize » Posts » Like and Comment Summary and pick a Color. The Text color in Hover State sets the color of the icons shown on hover.

Does the color stay after I click Load More?

Yes. The plugin runs the sbi_custom_js function again after Load More adds new posts. The new posts are colored too.

support

Couldn’t find your answer in the docs?

Contact Support