Site logo

Archived topic

Styling on comments gone, once auto-closure is in effect

3 replies · Started by Michael on June 3, 2021

Viewing posts 1–4 of 4

I noticed that comments on my blog are sometimes styled nicely (like at the moment of writing here) and sometimes they look like an unstyled list (like at the moment of writing here). Since I was sure that the one from the second post looked good once, too, I digged into it and noticed that if you have auto-closing of comments active (in my case, comments are deactivated after 21 days), the stylesheet containing comments-styling is disabled, too, it seems.

Is there a way to fix this easily? The condition for disabling the comments-stylesheet really should not be just based on the status "comments allowed or not", but on a combination of conditions that includes the presence of comments, too. Otherwise once nice looking comment-threads look like unstyled lists.

Thank you!

Hi there,

try adding this PHP snippet:

add_action( 'wp_enqueue_scripts', 'manual_comments_style_enqueue' );

function manual_comments_style_enqueue(){
	$comments = get_comments();
    if( $comments ) {
        $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
        $dir_uri = get_template_directory_uri();
        wp_enqueue_style( 'generate-comments', $dir_uri . "/assets/css/components/comments{$suffix}.css", array(), GENERATE_VERSION, 'all' );
    }
}

We'll take a look at the conditions in the theme

Works now! Thanks, David. (And yes, if you look into the theme conditions, please tell me so that I then can remove the snippet again.)

It will be updated in next Theme release version 3.1 :)
Glad to be of help

This archived topic is closed to new replies.