How to remove multiple items from content_for_header

Solved
Highlighted
New Member
2 0 0

Hey all,

So I get the idea of content_for_header however I've noticed some strange behaviour, especially with Facebook scripts, for some inexplicable reason I have three different Facebook connect scripts loading on every page with different ID's I can only assume this is because rather than overwriting the previous one the Facebook app has simply added another when I updated my details on it. I have seen in other threads people have been saying use something like this to remove them: 

 

{% capture h_content %}
 {{ content_for_header }}
{% endcapture %}

{{ h_content | remove: '123456789' }} 

 

However this seems to only work to remove a single item, if I try to remove both unused fb connect scripts one still remains as well as the one that I'm actually using. Can someone tell me how to remove multiple items from content for header please? 

It seems (according to the cheat sheets) that this isn't possible which is pretty strange, I would have thought that you might be able to pass an array of items to be passed to be removed, if there is a way of doing this that I'm not seeing please let me know.

Also in order to improve performance I would like to conditionally remove certain scripts when not on the homepage e.g. an instagram feed that I load at the bottom of the page, I can see the script is loaded on every page and I would like to stop this to help improve page load speeds on other pages. Could someone please help me with an example of how I might do this? 

 

Thanks

0 Likes
Highlighted
Shopify Expert
498 9 96

This is an accepted solution.

You're on the right track. To remove multiple items, just add more remove filters.

 

 

{% capture h_content %}
 {{ content_for_header }}
{% endcapture %}

{{ h_content | remove: '123456789' | remove: '987654321' | remove: ',"https:\/\/xxxxx.com\/xxxxx.js"' }} 

 

 

 

0 Likes
Highlighted
New Member
2 0 0

That worked perfectly!

Thank you!

0 Likes