We live in an age of collaborative work, and most of our daily jobs involve, one way or another, working with other people to get things done. If that's the case, then why not giving credit to every author that, for instance, has contributed to a blog post? In most CMS' this is not a native function. You either have to download a plugin or dive into the code to get it done.
With HubSpot, the case is especially challenging: it requires some tweaking behind the scenes, working with a combination of tags, HubDB and Hubl code to make things work. Granted, as is often the case with these custom solutions, we will lose some of the native features of the platform in favor of a unique feature. You will need to weigh in the advantages and disadvantages of going this route. In this post we'll dive deep into one possible solution to this problem.
Authors and tags
By default, HubSpot allows for only one author for blog posts. This is fine for your typical blog post, but sometimes you'll have a client that might require multiple authors for their entries. So how can we get over this limitation? The answer is: using tags.
Tags are attached to a blog post, and that is really is all we need to enable more than one author. For simplicity, let's do this step by step:
- Create a Universal Author (UA). This is how we'll call the regular HS Author that needs to be assigned to every post. We will not show this author in the posts, we're just creating this because every HubSpot blog needs an author. Thus, we won't be linking to this author in any page, so there won't be a author page or archive for this author. You will eventually need to create such a page to show the posts for your Tag Authors (TA). Feel free to name this UA however you like.
- Create tags for your posts authors (TA). Once you created the UA, you'll need to create the Tag Authors. To get this to work and correctly target in the backend with Hubl, you should add a unique prefix to the tags (such as author). We'll remove the prefix later so that the author name is displayed correctly. To do this, head to Blog>Tags and create a new tag, such as "author-John Doe".


Hubl Code to Display Authors
To display multiple authors on a blog post probably the most efficient way would be to create a Custom Module called "Multiple Authors" (or whatever you want to name it) that can be then used in different places throughout your website. You could also create a macro, which by the way is a cool feature that we should definitely use more often in our development process. In this case we have created a module that displays the author's name (and more data coming from the HubDB table, more on that in a minute):
{% if content.tag_list %}
<div class="info-tags">
<div class="author-imgs">
{% for tag in content.tag_list %}
{% if tag.slug is string_containing "author-" %}
{% set author_slug = tag|replace('author-', '', 1)|lower|replace(' ', '-') %}
{# get all rows #}
{% set all_rows = hubdb_table_rows('people') %}
{% set displayed = false %}
{% for row in all_rows %}
{% if row['hs_path'] == author_slug and not displayed %}
<div class="author-page">
<a href="{{ maindomain }}/authors/{{ row.hs_path }}"><img src="{{ row.avatar_image.url }}" alt="{{ row.hs_name }}"></a>
</div>
{% set displayed = true %}
{% endif %}
{% endfor %}
{% endif %}
{% endfor %}
</div>
<div class="info-author-date">
<div class="author-names">
{% for tag in content.tag_list %}
{% if tag.slug is string_containing "author-" %}
{% set author_slug = tag|replace('author-', '', 1)|lower|replace(' ', '-') %}
{# get all rows #}
{% set all_rows = hubdb_table_rows('people') %}
{% set displayed = false %}
{% for row in all_rows %}
{% if row['hs_path'] == author_slug and not displayed %}
<a href="{{ maindomain }}/authors/{{ row.hs_path }}">{{ row.hs_name }}</a><span class="separator">,</span>
{% set displayed = true %}
{% endif %}
{% endfor %}
{% endif %}
{% endfor %}
<time datetime="{{ content.publish_date|escape_attr }}" class="blog-post__timestamp">
{{ content.publish_date_local_time.strftime('%d') }}
{{ content.publish_date_local_time.strftime('%B') }},
{{ content.publish_date_local_time.strftime('%Y') }}
</time>
</div>
</div>
</div>
{% endif %}
In this example for the module.html code for the Multiple Authors custom module we are firstly getting the tags from the content.tag_list function that is available directly in the blog post. This will get us a list of all tags associated to the post, that we obviously will need to filter. That's where the different Hubl filters come in handy. First we run a for loop through all the tags with {% for tag in content.tag_list %}
. Then we get specific tags that contain the keyword "author-": {% if tag.slug is string_containing "author-" %}.
Then we actually get rid of the "author-" string so that we keep the name of the author and nothing else: {% set author_slug = tag|replace('author-', '', 1)|lower|replace(' ', '-') %}
. But, of course, you might be wondering: but why are we setting a variable called "author_slug" instead of displaying the name directly? Come in the HubDB table integration.
HubDB to put it all together
If you've never worked with HubDB and the creation of dynamic pages using it, I strongly suggest you take a look at the documentation to get familiarized with the process. The main idea here is to create dynamic author pages that will be populated from HubDB: this way we can use the power of this relational database to create dynamically generated pages to display everything we need from our authors (name, slug, bio, profile image, etc). We won't go over the creation of this table in this blog post, but you should come up with something similar to this:

The key here is that we are going to use the Page Path of the table to match it with the "author_slug" variable we set, in this way linking the author tag with the entries in the table (of course, they need to match exactly). That is what these lines of code are achieving here:{% set all_rows = hubdb_table_rows('people') %}
{% set displayed = false %}
{% for row in all_rows %}
{% if row['hs_path'] == author_slug and not displayed %}
In those lines we get all rows from the table first, assign a displayed variable to avoid repetitions, and then iterate through all the rows and get the rows that match with the tags associated with the post. Then we can get the data we need from the HubDB, such as author name, slug, profile image, etc. We can display this data however we want by putting it into curly braces as you would normally do in hubl language (such as {{ row.hs_name }}).
Conclusion
The process to add multiple authors might not seem simple at a first glance, and of course it is not as elegant as simple assigning authors from the blog post itself . However, this solution, even if it requires a bit of work and thinking, enables you to not only display multiple authors on posts but also to create dynamic author pages from the HubDb table, allowing you to format those pages however you want. More on that coming soon!