Blog, Website & Page Publishing

Woodsy
Top Contributor

Remove Link from Blog Authors Name

SOLVE

Hi, is there a way to remove the link from a blog authors name if they have only written one blog? Currently all blog authors names link to a page deicated to all the posts they have written. 

Woodsy_0-1725961141953.png

 

 

 <h4>Written by <a class="author-link" href="{{ group.absolute_url }}/author/{{ content.blog_post_author.slug }}">{{ content.blog_post_author.display_name }}</a></h4> 

 

 


Is there a way to rewrite the above code so that it checks to see how many blogs the author has written? Or is there a way in the Hubspot blog author table to added a checkbox to turn this feature on or off depending on the number of blogs an author has written?

Thanks

0 Upvotes
2 Accepted solutions
albertsg
Solution
Guide

Remove Link from Blog Authors Name

SOLVE

Hello @Woodsy

That's an interesting request! I haven't done this myself but it should be possible if you use blog_recent_author_posts and check the length of the returned value. 

Try something like this:

 

{% set author_posts = blog_recent_author_posts("default", content.blog_post_author.slug, 5) %}


{% if author_posts|length > 1 %}
    <h4>Written by <a class="author-link" href="{{ group.absolute_url }}/author/{{ content.blog_post_author.slug }}">{{ content.blog_post_author.display_name }}</a></h4> 
{% else %}
    <h4>Written by {{ content.blog_post_author.display_name }}</h4> 
{% endif %}

 

The code above stores the 5 most recent articles for the author of the blog under the author_posts variable and then checks its length to decide if it should show a link or not. 

If the author has more than 1 article, it will show the link, otherwise it won't. 

 

Let me know if that helps! 🙂



Did my answer help you? Mark it as a solution


Do you need help with your site? Book time with me:


Book time with Albert

You can also connect with me on LinkedIn



View solution in original post

Anton
Solution
Thought Leader | Partner
Thought Leader | Partner

Remove Link from Blog Authors Name

SOLVE

Hi @Woodsy

you can try using the blog_recent_author_posts function for this.

The code would look something like this:

{% set author_posts = blog_recent_author_posts("default", content.blog_post_author.slug, 200) %}

{% if author_posts > 1 %}
   <h4>Written by <a class="author-link" href="{{ group.absolute_url }}/author/{{ content.blog_post_author.slug }}">{{ content.blog_post_author.display_name }}</a></h4>
{% else %}
   <h4>Written by {{ content.blog_post_author.display_name }} </h4>
{% endif %}

 

I'd recommend to put this code inside a custom module since it will give you more flexibility and (a bit better usability) in the long run. It would also allow you to add a lot of modifcations for later use.

For instance:

  • You could add a blog select option if you have several blogs (or planning to have several ones)
  • You could add a number field to manually change the amount per blog listing. For instace you'd like to check for more than 1 post in "BLOG A" but for more than 5 posts in "BLOG B"...

 

best, 

Anton

 

Anton Bujanowski Signature

View solution in original post

7 Replies 7
Anton
Solution
Thought Leader | Partner
Thought Leader | Partner

Remove Link from Blog Authors Name

SOLVE

Hi @Woodsy

you can try using the blog_recent_author_posts function for this.

The code would look something like this:

{% set author_posts = blog_recent_author_posts("default", content.blog_post_author.slug, 200) %}

{% if author_posts > 1 %}
   <h4>Written by <a class="author-link" href="{{ group.absolute_url }}/author/{{ content.blog_post_author.slug }}">{{ content.blog_post_author.display_name }}</a></h4>
{% else %}
   <h4>Written by {{ content.blog_post_author.display_name }} </h4>
{% endif %}

 

I'd recommend to put this code inside a custom module since it will give you more flexibility and (a bit better usability) in the long run. It would also allow you to add a lot of modifcations for later use.

For instance:

  • You could add a blog select option if you have several blogs (or planning to have several ones)
  • You could add a number field to manually change the amount per blog listing. For instace you'd like to check for more than 1 post in "BLOG A" but for more than 5 posts in "BLOG B"...

 

best, 

Anton

 

Anton Bujanowski Signature
albertsg
Guide

Remove Link from Blog Authors Name

SOLVE

@Anton I'm blown away that we posted the same code at the same time! 😂 I think it's safe to say this is the solution!



Did my answer help you? Mark it as a solution


Do you need help with your site? Book time with me:


Book time with Albert

You can also connect with me on LinkedIn



Anton
Thought Leader | Partner
Thought Leader | Partner

Remove Link from Blog Authors Name

SOLVE

Ok - wow. 😂

 

 

Anton Bujanowski Signature
kennedyp
Community Manager
Community Manager

Remove Link from Blog Authors Name

SOLVE

LOL love this! Thanks so much to both of you for your help 😂


Did you know that the Community is available in other languages?
Join regional conversations by changing your language settings !
albertsg
Solution
Guide

Remove Link from Blog Authors Name

SOLVE

Hello @Woodsy

That's an interesting request! I haven't done this myself but it should be possible if you use blog_recent_author_posts and check the length of the returned value. 

Try something like this:

 

{% set author_posts = blog_recent_author_posts("default", content.blog_post_author.slug, 5) %}


{% if author_posts|length > 1 %}
    <h4>Written by <a class="author-link" href="{{ group.absolute_url }}/author/{{ content.blog_post_author.slug }}">{{ content.blog_post_author.display_name }}</a></h4> 
{% else %}
    <h4>Written by {{ content.blog_post_author.display_name }}</h4> 
{% endif %}

 

The code above stores the 5 most recent articles for the author of the blog under the author_posts variable and then checks its length to decide if it should show a link or not. 

If the author has more than 1 article, it will show the link, otherwise it won't. 

 

Let me know if that helps! 🙂



Did my answer help you? Mark it as a solution


Do you need help with your site? Book time with me:


Book time with Albert

You can also connect with me on LinkedIn



Woodsy
Top Contributor

Remove Link from Blog Authors Name

SOLVE

Thank you for taking the time to look into this for me. I have aded the code into my html but am getting an error:

Woodsy_0-1727174746905.png



The error console isn't much help:

Woodsy_1-1727174778128.png


If I remove this part of the code the error resolves:

 

{% set author_posts = blog_recent_author_posts("default", content.blog_post_author.slug, 200) %}

 


Not sure what to do as the error isn't giving me much to go on. Ihave tried placing this line of code above the other code.  I have also placed it at the start of the HTML.

Thank you in advance for any further guidance.

0 Upvotes
kennedyp
Community Manager
Community Manager

Remove Link from Blog Authors Name

SOLVE

Hey @Woodsy! Thanks for your post. Let's invite some of our experts to see if they have any suggestions! 

 

@Jnix284, @Anton, @DaniellePeters -- do any of you know how we might remove the link from the author name on select blog posts? Ideally, we could make this dynamic based on the total blog posts they've written. All workarounds are welcome! Thanks 😊

 

Best, 
Kennedy


Did you know that the Community is available in other languages?
Join regional conversations by changing your language settings !