(Squarespace) Two font families in One sentence

You have a heading like this. You need to change “Just” and “Earth” to two different font.

#1. Wrap word with these symbols.

#2. Use this code to Code Injection > Footer.
If code doesn’t work, you can comment below, message or send me an email.

<script>
document.addEventListener("DOMContentLoaded", function() {
  const bodyContent = document.body;
  
  function processElement(element) {
    if (element.nodeType === Node.TEXT_NODE) {
      if (element.nodeValue.includes('#') || element.nodeValue.includes('$')) {
        const tempDiv = document.createElement('div');
        let content = element.nodeValue;
        
        content = content.replace(/#([^#]+)#/g, '<span class="font1">$1</span>');
        content = content.replace(/\$([^\$]+)\$/g, '<span class="font2">$1</span>');
        
        tempDiv.innerHTML = content;
        
        const fragment = document.createDocumentFragment();
        while (tempDiv.firstChild) {
          fragment.appendChild(tempDiv.firstChild);
        }
        
        element.parentNode.replaceChild(fragment, element);
      }
    } else if (element.nodeType === Node.ELEMENT_NODE) {
      const skipTags = ['SCRIPT', 'STYLE', 'TEXTAREA', 'INPUT'];
      if (!skipTags.includes(element.tagName)) {
        Array.from(element.childNodes).forEach(child => {
          processElement(child);
        });
      }
    }
  }
  
  processElement(bodyContent);
});
</script>

#3. Use this code to Custom CSS. Replace monospace & Beth Ellen with your desired fonts.

span.font1 {
    font-family: monospace;
}
span.font2 {
    font-family: "Beth Ellen";
}

#4. Result

1 Like

@tuanphan,

:heart: :heart: :heart: