How to Load Script on One Domain and Exclude Previews in HubSpot [HubL Snippet]

The HubL code below will help you scope heatmap or anlytics tracking on one domain and exclude any previews. {% if request.domain == ‘www.yourdomain.com’ and request.query is not string_containing ‘hs_preview’ %} {% endif %}

Continue Reading

Category: Code Snippets

How to Quickly Search for a Code Text String on Entire WordPress Website

I recently was trying to optimize my WordPress site performance and noticed a javascript error saying jQuery is not defined. Basically, there was a script that was loading before jQuery was loaded. I searched my entire theme but could not find the code. I then thought of searching all of my plugins for the code…. Read more »

Continue Reading

Category: Code Snippets

How to Improve LCP Mobile Speed Score

I was recently trying to improve my LCP on mobile and was running into poor performance for LCP and CLS scores. I narrowed things down to most of my blog posts having a featured image floated in the top right. When you viewed the image on mobile the thumbnail didn’t really make sense and wasn’t… Read more »

Continue Reading

Category: Code Snippets

Use is_in_editor to Add Inline Comments and Notes Only in the HubSpot Editor [code snippet]

As a HubSpot CMS developer, you sometimes need to add some contextual information in templates to make it easier for content editors to know where and how to edit things. Add the code below into a template to display help text only when editing the HubSpot template. {% if is_in_editor %} <style>.hseditor-help {background:#FFFFE0;padding:1rem;text-align:center;}</style> <div class=”hseditor-help”>… Read more »

Continue Reading

Category: Code Snippets

How to Format a Phone Number in HubSpot CMS HubL

I was recently working on a custom HubSpot quote theme and needed to format the phone number. By default, the number was displayed as a long string of numbers without any parenthesis or number groupings. The code below uses a HubL to display a subset of the full string in the chunks you need it… Read more »

Continue Reading

Category: Code Snippets

HubSpot HubL Code Snippet Collection – Filters, Functions, and Macros

Below is a list of my commonly used HubSpot CMS HubL filters, functions, and Macros. Email me if you have one you would like to add to this list. Create a slug from a text string I used this when I wanted to add a CSS class name to the li of a menu using… Read more »

Continue Reading

Category: Code Snippets

FAQ Schema Microdata Code Snippet

Below is a FAQ microdata schema code template you can copy and paste and add to your page HTML. You would repeat the .faq-question div block for each QA answer set. Once you are done adding your markup you can test it in the Google schema tester. If you are using WordPress, I noticed the… Read more »

Continue Reading

Category: Code Snippets

How to Copy HubSpot Sections Into a HubL Code Template

HubSpot CMS has recently added the ability to copy sections built with the visual editor and then paste the HubL code into a template. Previously, this had to be done by manually. Why you might want to use this A designer or marketer could visually design the page. Get 80% there and then hand off… Read more »

Continue Reading

Category: Code Snippets

Make YouTube Embeds Responsive in WordPress [code snippet]

The CSS styles below will make any YouTube video embeds using just the URL responsive. Add this to the bottom of your WordPress theme CSS stylesheet. .embed-youtube{ position: relative; padding-bottom: 56.25%; height: 0; overflow: hidden; max-width: 100%; } .embed-youtube iframe, .embed-youtube object, .embed-youtube embed { position: absolute; top: 0; left: 0; width: 100%; height: 100%;… Read more »

Continue Reading

Category: Code Snippets

How to Add Language Code Next to HubSpot Language Dropdown

By default, when you visit a page with a translation, it displays a globe icon. I thought it would be more helpful to have a visual cue for your current language. So I wrote the code below to add the current language code next to the globe icon. Javascript Add this to your main theme… Read more »

Continue Reading

Category: Code Snippets