Skip to content

Instantly share code, notes, and snippets.

@paulmason
Last active March 15, 2024 13:06
Show Gist options
  • Star 12 You must be signed in to star a gist
  • Fork 8 You must be signed in to fork a gist
  • Save paulmason/f93c40a7086288afeb65a4c01977c0a6 to your computer and use it in GitHub Desktop.
Save paulmason/f93c40a7086288afeb65a4c01977c0a6 to your computer and use it in GitHub Desktop.

Disabling all apps code loaded via content_for_header

Apps are all loaded in the header via a single script call, then the remaining assets are loaded below. This process takes place in the liquid tag content_for_header.

  1. Open theme.liquid and locate the line which reads {{ content_for_header }}.

  2. Now you can paste the following block of code to disable all apps on a new line before {{ content_for_header }}.

{% comment %} Leave url_to_remove as 0 to remove all apps, or set to a number to remove a specific app. {% endcomment %}
  {% assign url_to_remove = 0 %}
  {% assign lines = content_for_header | newline_to_br | split: '<br />' %}
  
  {% for line in lines %}
    {% if line contains 'var urls' %}
      {% if url_to_remove == 0 %}
        {% comment %}Remove all apps{% endcomment %}
        {% capture new_line %}
        {% endcapture %}
        {% assign empty_array = new_line | append: "var urls = [];" %}
        {% assign content_for_header = content_for_header | replace: line, empty_array %}
        <!-- Removed all apps. -->
      {% else %}
        {% assign url_string = line | remove: "var urls = [" | remove: "];" | strip %}
        {% assign url_array = url_string | split: ',' | uniq %}
        {% comment %}Just remove app at index 'url_to_remove' {% endcomment %}
          {% for url in url_array %}
            {% if forloop.index == url_to_remove %}
              {% assign content_for_header = content_for_header | replace: url, '""' %}
              <script>
                console.log(
                  '%c Removed app no. {{ url_to_remove }} of {{ url_array.size }}: {{ url }}',
                  'color: #87C378'
                );
             </script>
          {% endif %}
        {% endfor %}
      {% endif %}
    {% endif %}
  {% endfor %}
  1. Save theme.liquid. The above code will remove the assets of all apps enabled on the account by removing them from {{ content_for_header }}, so will disable every app which is loaded through there.

Disabling Individual Apps

If we want to discover which of the 17 apps a store has installed is breaking everything we can disable apps one by one to troubleshoot.

  1. Use the same block of code mentioned above, but don't save theme.liquid yet.

  2. Now change the value of the liquid variable url_to_remove to a number to disable that specific app (e.g. changing it to 3 will disable the 3rd app enabled by {{ content_for_header }}, leaving the value as 0 will disable all apps). Now you can start running through each app to troubleshoot that issue.

  3. Visit the storefront in Google Chrome when you have an app disabled and use the inspect tool to search in the storefront's code for the following text: Removed app no.. You can repeat this step, disabling each app on the store 1 by 1 until you find the one causing the issue.

@dpanfili
Copy link

This only works on disabling Free apps?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment