A way to hide commento in pinned posts?

Hello there! I’m using commento as a comment section on my blog using the code:

// src: https://cdn.commento.io/js/commento.js

var topP = document.createElement("p");
topP.innerHTML = '<div id="commento"></div>';
var cont = document.getElementById("wrapper");
cont = document.getElementById("post-body");

if (cont !== null) {
cont.appendChild(topP);
}

I was wondering if anyone knew a way I could hide it from pinned posts on my blog?

You could hide it by checking to see the url of the current page. If it matches the url for a pinned post, then don’t render the comments box. For instance, if you had an “About” page at /about and an “Archive” page at /archive, and those pages were pinned, you can do something like this:

// src: https://cdn.commento.io/js/commento.js

var topP = document.createElement("p");
topP.innerHTML = '<div id="commento"></div>';
var cont = document.getElementById("wrapper");
cont = document.getElementById("post-body");

var currentURL = window.location.href;
var isAboutPage = /\/about$/i.test(currentURL);
var isArchivePage = /\/archive$/i.test(currentURL);

if (cont !== null && !isAboutPage && !isArchivePage) {
cont.appendChild(topP);
}
1 Like

@dino I just used this solution and it worked perfectly. Thank you :grinning:

You are welcome!

1 Like