Skip to content

Instantly share code, notes, and snippets.

@amk221
Last active May 28, 2021 15:11
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save amk221/6999721 to your computer and use it in GitHub Desktop.
Save amk221/6999721 to your computer and use it in GitHub Desktop.
Shopify shortcodes, post meta and featured images

Shopify shortcodes, post meta and featured images

Example

Hello World this is an example Shopify blog post with a [my_shortcode].
Lorem ipsum dolor sit amet, consectetur [another_shortcode] elit. Proin vel lacinia nunc,
id elementum leo. Donec eget lacus sed dui interdum mollis.
<!--meta-->
<!--featured_image--> http://placehold.it/640x480 <!--/featured_image-->
<!--something_else--> Some other meta data <!--/something_else -->

In the blog template

Ignore all article content preceding Then pull out the individual meta tags...

{% capture meta %}{{ article.content }}{% endcapture %}
{% assign metas = meta | split: "<!--meta-->" | size %}
{% if metas == 2 %}

    {% assign featured_image = meta | split: "<!--featured_image-->" | last | split: "<!--/featured_image-->" | first %}
    {{ featured_image }}

    {% assign something_else = meta | split: "<!--something_else-->" | last | split: "<!--/something_else-->" | first %}
    {{ something_else }}

{% endif %}

In the article template

Include your shortcodes...

{% capture my_shortcode %}{% include 'my_shortcode' %}{% endcapture %}
{% capture another_shortcode %}{% include 'another_shortcode' %}{% endcapture %}

Process the shortcodes...

{% capture content %}{{ article.content }}{% endcapture %}
{% assign content = content | replace: '[my_shortcode]', my_shortcode %}
{% assign content = content | replace: '[another_shortcode]', another_shortcode %}

Render the content, ignoring everything after

{% assign content = content | split: "<!--meta-->" | first %}
{{ content }}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment