Skip to content

Instantly share code, notes, and snippets.

@vevgeniy85
vevgeniy85 / main.js
Created March 21, 2023 10:59
JavaScript - Set profile image as first letters of first and last name
function showAuthorInitials(containerSelector, blockSelector, attribute) {
const container = document.querySelector(containerSelector);
const blocks = container.querySelectorAll(blockSelector);
for (let i = 0; i < blocks.length; i++) {
const block = blocks[i];
const value = block.getAttribute(attribute);
const words = value.split(" ");
let initials = "";
@vevgeniy85
vevgeniy85 / shopify-section-ab.liquid
Created October 24, 2022 15:35 — forked from evulse/shopify-section-ab.liquid
This needs to be installed in your theme as a section
{% javascript %}
function loadSection() {
var elArray = Array.prototype.slice.call(document.querySelectorAll(".shopify-section-ab"));
if (window.parent.ThemeEditor !== undefined) {
elArray.forEach(function(el) {
el.classList.remove("ssab-neither");
el.classList.add("ssab-editor");
});
} else {
var cookie = "";
@vevgeniy85
vevgeniy85 / related-articles.liquid
Created July 20, 2022 09:11 — forked from atikju/related-articles.liquid
Show related articles based on article tags - Shopify
@vevgeniy85
vevgeniy85 / shortcode-readmore.liquid
Created June 1, 2022 08:25
Shopify - shortcode-readmore
{%- comment -%}
@param before_readmore {Boolean}
Output the contents of the text before the readmore shortcode
{%- endcomment -%}
{%- assign readmore_split = text | split: '<!-- more -->' -%}
{%- if before_readmore -%}{{- readmore_split[0] -}}{%- else -%}{{- readmore_split[1] -}}{%- endif -%}
@vevgeniy85
vevgeniy85 / product.liquid
Created March 16, 2022 07:12
Shopify - Add Product Image
{% for image in product.media %}
<img src="{{ image.preview_image | img_url: '900x' }}" alt="{{ image.alt | default: product.title | strip_html | escape }}">
{% endfor %}
@vevgeniy85
vevgeniy85 / structured-data.liquid
Created February 22, 2022 17:20
Shopify Structured Data
{% comment %}
Article structured data
https://developers.google.com/search/docs/data-types/articles
{% endcomment %}
{% if template contains 'article' %}
{%- capture article_description -%}
{%- if article.excerpt != blank -%}
{{ article.excerpt | strip_html }}
{%- else -%}
@vevgeniy85
vevgeniy85 / delete_404_attachments.php
Created February 6, 2022 07:58 — forked from sabrina-zeidan/delete_404_attachments.php
Clean Media Library from broken images. Delete attachments which files no longer available and return 404 error [Wordpress]
function delete_404_attachments(){
$attachments = get_posts( array(
'post_type' => 'attachment',
'numberposts' => -1,
'fields' => 'ids'
));
if ($attachments) {
foreach ($attachments as $attachmentID){
$file_url = wp_get_attachment_url( $attachmentID);
$file_headers = @get_headers($file_url);
@vevgeniy85
vevgeniy85 / template-article.liquid
Last active January 6, 2022 12:05
Article Featured Image with SRCSET - Shopify 2.0
{%- if article.image -%}
<div class="article-template__hero-container" {{ block.shopify_attributes }}>
<div class="article-template__hero-{{ block.settings.image_height }} media"
itemprop="image"
{% if block.settings.image_height == 'adapt' and article.image %} style="padding-bottom: {{ 1 | divided_by: article.image.aspect_ratio | times: 100 }}%;"{% endif %}
>
<img
srcset="{% if article.image.width >= 350 %}{{ article.image | img_url: '350x' }} 350w,{% endif %}
{% if article.image.width >= 750 %}{{ article.image | img_url: '750x' }} 750w,{% endif %}
{% if article.image.width >= 1100 %}{{ article.image | img_url: '1100x' }} 1100w,{% endif %}
@vevgeniy85
vevgeniy85 / product.liquid
Last active December 29, 2021 12:58
Add new snippet klaviyo-tracking.liquid, paste code and include snippet {% include 'klaviyo-tracking' %} to product.liquid template
<script type="text/javascript">
var _learnq = _learnq || [];
var item = {
Name: {{ product.title|json }},
ProductID: {{ product.id|json }},
Categories: {{ product.collections|map:'title'|json }},
ImageURL: "https:{{ product.featured_image.src|img_url:'grande' }}",
URL: "{{ shop.secure_url }}{{ product.url }}",
Brand: {{ product.vendor|json }},
Price: {{ product.price|money|json }},
@vevgeniy85
vevgeniy85 / widget-google-anti-flicker.liquid
Created December 22, 2021 12:45
Anti-flicker snippet
<!-- Anti-flicker snippet (recommended) -->
<style>.async-hide {
opacity: 0 !important
} </style>
<script>
(function (a, s, y, n, c, h, i, d, e) {
s.className += ' ' + y;
h.start = 1 * new Date;
h.end = i = function () {
s.className = s.className.replace(RegExp(' ?' + y), '')