Add Custom Icons to Shopify Product Pages Without Apps

Published on Jul 26, 2024

By Liam Gallagher

#Shopify#E-commerce#Web Development
From above crop adult male packing ordered product or gift in white cardboard box with craft paper for safety postal delivery at white marble table

Are you looking to enhance your Shopify product pages with custom icons like warranty badges or organic certifications? You’re in the right place. This guide will walk you through the process of adding custom icons to your product pages using Shopify’s powerful metafield feature, without relying on third-party apps.

Understanding Metafields in Shopify

Before we dive into the implementation, let’s briefly explore what metafields are and why they’re useful for this task.

What are Metafields?

Metafields in Shopify are additional pieces of data that can be attached to various objects in your store, such as products, collections, or orders. They allow you to store custom information that isn’t covered by Shopify’s standard fields.

Why Use Metafields for Custom Icons?

Using metafields for custom icons offers several advantages:

  1. Flexibility: You can easily add, modify, or remove icons without changing your theme code.
  2. Scalability: Metafields can be applied to individual products or entire collections.
  3. Performance: Unlike apps, metafields don’t add extra load to your store.

Implementing Custom Icons with Metafields

Now, let’s explore how to add custom icons to your product pages using metafields.

Method 1: Conditional Display Based on Metafield Values

This method involves checking the value of a metafield and displaying the corresponding icon.

Step 1: Create the Metafield

First, you’ll need to create a metafield for your products. You can do this through the Shopify admin or via the API.

Step 2: Add Liquid Code to Your Product Template

Add the following Liquid code to your product template file:

{% if product.metafields.custom.warranty %}
  {% case product.metafields.custom.warranty %}
    {% when '1 year warranty' %}
      <img src="{{ 'one-year-warranty.svg' | asset_url }}" alt="1 Year Warranty">
    {% when '2 year warranty' %}
      <img src="{{ 'two-year-warranty.svg' | asset_url }}" alt="2 Year Warranty">
  {% endcase %}
{% endif %}

This code checks the value of the warranty metafield and displays the appropriate icon.

Method 2: Using SVG or Custom Fonts in Metafields

Another approach is to store the SVG code or a custom font character directly in the metafield.

Step 1: Create the Metafield

Create a metafield to store your SVG code or custom font character.

Step 2: Display the Icon

Add this Liquid code to your product template:

{% if product.metafields.custom.icon %}
  {{ product.metafields.custom.icon }}
{% endif %}

This will output the SVG code or custom font character stored in the metafield.

Advanced Customization Using Theme Settings

While metafields offer a great solution, you can take it a step further by utilizing theme settings for even more flexibility.

Creating Custom Settings

To create custom settings for your icons:

  1. Open your theme’s settings_schema.json file.
  2. Add the following code at the bottom of the file:
{
  "name": "Custom Icons",
  "settings": [
    {
      "type": "image_picker",
      "id": "warranty_icon",
      "label": "Warranty Icon"
    },
    {
      "type": "image_picker",
      "id": "organic_icon",
      "label": "Organic Icon"
    }
  ]
}

Uploading and Displaying Icons

After adding the settings:

  1. Go to your theme settings in the Shopify admin.
  2. Upload your icons in the new “Custom Icons” section.
  3. Add this Liquid code to your product template:
{% if settings.warranty_icon %}
  <img src="{{ settings.warranty_icon | img_url: 'master' }}" alt="Warranty Icon">
{% endif %}

{% if settings.organic_icon %}
  <img src="{{ settings.organic_icon | img_url: 'master' }}" alt="Organic Icon">
{% endif %}

This method allows you to easily manage your icons through the theme settings, providing a user-friendly interface for updates.

Best Practices for Custom Icons

When implementing custom icons on your Shopify product pages, keep these best practices in mind:

Optimize for Performance

  1. Use SVG format for icons when possible, as they’re scalable and lightweight.
  2. Compress your images to reduce load times.
  3. Lazy load icons that are below the fold to improve initial page load speed.

Maintain Consistency

  1. Ensure your custom icons match your overall brand aesthetic.
  2. Use a consistent style and color scheme across all icons.
  3. Keep icon sizes uniform for a polished look.

Accessibility Considerations

  1. Always include descriptive alt text for your icons.
  2. Ensure sufficient color contrast for visibility.
  3. Don’t rely solely on icons to convey important information; use accompanying text when necessary.

By following these guidelines, you’ll create a more professional and user-friendly experience on your product pages.

Troubleshooting Common Issues

Even with careful implementation, you might encounter some challenges. Here are solutions to common problems:

Icons Not Displaying

If your icons aren’t showing up:

  1. Double-check that your metafield or theme setting names match exactly in your Liquid code.
  2. Verify that your image URLs are correct if using external images.
  3. Clear your theme cache and refresh your browser.

Inconsistent Appearance Across Devices

To ensure your icons look great on all devices:

  1. Use responsive design techniques in your CSS.
  2. Test on various screen sizes and browsers.
  3. Consider using different icon sizes for mobile and desktop views.

Slow Page Load Times

If adding icons is impacting your page speed:

  1. Optimize your images further.
  2. Consider using icon fonts instead of individual image files.
  3. Implement lazy loading for icons below the fold.

By addressing these common issues, you’ll ensure a smooth implementation of custom icons on your Shopify product pages.

Remember, while metafields and theme settings offer powerful solutions for adding custom icons, always test thoroughly and consider the impact on your store’s performance and user experience. With careful implementation, custom icons can significantly enhance your product pages and help your products stand out in the competitive e-commerce landscape.

Take Our Quick Quiz:

Which primary product image do you think has the highest conversion rate?