Bartran
Bartran

Reputation: 1

How to remove a word from a Blogger label

I've almost found a good workaround for Blogger's lack of a categories field. I use the "contains" operator to filter all labels that contain "Category" into a Categories list and "not contains" to put the remaining labels into a Tags list.

My code within the post loop looks like this:

          Categories:
              <b:loop values='data:post.labels where (l =&gt; l.name contains &quot;Category&quot;)' var='label'>
            <a expr:href='data:label.url' rel='tag'><data:label.name/></a>, 
          </b:loop>
          Tags:
          <b:loop values='data:post.labels where (l =&gt; l.name not contains &quot;Category&quot;)' var='label'>
            <a expr:href='data:label.url' rel='tag'><data:label.name/></a>, 
          </b:loop>

So, a post with labels "Category Art, Zebra, Category Tea, Category Junk, Banana, Arrow," will output "Categories: Category Art, Category Junk, Category Tea, Tags: Arrow, Banana, Zebra,"

I would like it to look a bit cleaner by removing or hiding the "Category" part from the label name after the labels have been sorted. Is there any way of doing this within Blogger's backend or do I have to use JavaScript?

Upvotes: 0

Views: 79

Answers (1)

user6144987
user6144987

Reputation:

You can do this using only JavaScript

document.querySelectorAll('a[rel=tag]').forEach((e) => {
        e.innerText = e.innerText.replace('Category','');
});

Upvotes: 1

Related Questions