Skip to content

Add "author" badge to NodeBB posts using either CSS or jQuery

Customisation
  • I thought I had already created a dedicated thread for this elsewhere, but clearly not - it was probably bundled in with another topic.

    If you want to create an “Author” badge on each post that looks like the below, you can do this using pure CSS

    d983d994-c4b6-4063-ae1e-74bba88d75b5-image.png

    Required CSS

    .topic-owner-post [itemprop=name]:after {
        border: 2px solid var(--bs-border-color);
        border-radius: 0.25rem !important;
        color: var(--bs-body-color);
        content: "Author";
        margin-left: 5px;
        padding: 2px 10px;
        display: inline-block;
    }
    

    However, things get slightly more complicated if you want to add an icon in the same element, like the below

    a81318a0-a15c-45f1-94f7-ee17a1931433-image.png

    As the above example makes use of the :after pseudo element, it’s not possible to have two font-family statements when using content: ""

    To facilitate this, you’d need a jQuery function that looks like the below

    $(document).ready(function() {
        $(window).on('action:ajaxify.end', function(data) {
            $(".topic-owner-post [itemprop=name]").append("<span class='author'><span class='author-icon'><i class='fa-light fa-bullhorn'></i>Author</span>");
        });
    });
    

    Here, you use span tags to insert both the icon, and text 🙂

    Obviously, you need to ensure that the css for .author and .author-icon exist.

    Here’s an example

    span.author {
        border: 2px solid var(--bs-border-color);
        border-radius: 0.25rem !important;
        color: var(--bs-body-color);
        content: "Author";
        margin-left: 5px;
        padding: 2px 10px;
        display: inline-block;
    }
    span.author-icon i {
        margin-right: 5px;
    }
    
  • phenomlabundefined phenomlab referenced this topic on