Posts Categorized: Code Snippets
Product Schema for B2B Products that Require Requesting a Quote [HubSpot CMS Code]
Category: Code Snippets
As HubSpot CMS developers, enhancing your page’s SEO and visibility in search engines is key. One way to do this is by adding structured data markup using JSON-LD. Here’s a quick snippet you can use to add structured data for a product on your HubSpot page: Change “b2bcompany” to your specific company name and domain… Read more »
HubSpot HubL: Handling All URL Types in a Button Module Using URL Field
Category: Code Snippets
When building HubSpot modules, handling different URL types correctly is essential for a seamless user experience. HubSpot’s URL field supports multiple types, including external links, internal content, files, emails, phone numbers, and even WhatsApp. To ensure your button links work as expected across all these types, you can use the following HubL code snippet. This… Read more »
How to Track Internal Link Clicks in GA4 (With and Without Google Tag Manager)
Category: Code Snippets
It’s important to note that GA4 doesn’t track internal link clicks by default. If you want to gather valuable data on how users are navigating your site, tracking internal link clicks is a must. Understanding which pages users are clicking on, where they go next, and which calls to action are the most effective can… Read more »
HubSpot Module Code Snippet: Convert Alignment Fields to CSS Flex Properties [HubL Macro]
Category: Code Snippets
Below are macros you can use in your HubSpot CMS development projects to convert a text align field into flexbox justify content values. Sometimes text alignment and it’s icons are easier for content editors to understand. So when building functionality you may need to convert it into flexbox values like I have done here. HubL… Read more »
How to publish a page in development mode without HubSpot content staging [code snippet]
Category: Code Snippets
HubSpot has a nice feature called content staging which prevents search engines form crawling and indexing the content. But if you are using HubSpot CMS starter you won’t have access to this tool. So a work around is to add the following code to the HEAD of your base layout HTML file. This adds the… Read more »
HubSpot Custom Module Boilerplate Code Snippet
Category: Code Snippets
Below is a some boilerplate code to use when creating a custom module inside HubSpot CMS. {# HubSpot uses different prefixes so this just gets the number module_######### widget_######### outputs just the number #} {% set instanceID = name[7:] %} {{ instanceID }} <div class=”module-class” id=”module{{instanceID}}”> <div class=”row-fluid”> <div class=”span6″>A</div> <div class=”span6″>B</div> </div> </div> {%… Read more »
Set Variable Values in a Loop and Use Elsewhere HubL HubSpot
Category: Code Snippets
When customizing a custom HubSpot quote template you may want to know what line items are present in the quote. You can then create conditional logic with a set of known values. The only problem is when you set a variable inside a loop it is not able to be referenced outside of the loop… Read more »
HubSpot Related Posts Based on Tag Module [Code Snippet]
Category: Code Snippets
The code snippet below lists related posts based on the current post tags used. The HubSpot developer docs has a code example using a Javascript formatter but I was unable to get this to resize the featured image. So I created the code below to use a HubL macro instead. HubSpot Module HTML + HubL… Read more »
How to Load Script on One Domain and Exclude Previews in HubSpot [HubL Snippet]
Category: Code Snippets
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 %}
How to Quickly Search for a Code Text String on Entire WordPress Website
Category: Code Snippets
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 »