Site logo

Archived topic

Comments disabled but style messed up

8 replies · Started by Gianluca on April 5, 2021

Viewing posts 1–9 of 9

Hi,

On my website I'd like to disable comments for old posts without deleting them.

If I disable the possibility to comments on old posts as explained here https://docs.generatepress.com/article/removing-comments/ the style of existing comments is messed up, as you can see in the following screenshots:

Comments enabled https://imgur.com/a/Pa9EGzv
Comments disabled https://imgur.com/a/t2PnIET

Do you know how to disable comments, without deleting them, while keeping the original style for existing comments?

Thank you in advance,

Gianluca

Hi there,

That's strange. I don't think it's a theme issue though.

Couple things to test:

- Does the same issue happen on every post or just this specific post?

- Does the same issue happen with a Twenty series default wp theme?

Hi Leo,

it happens on every post if I disable comments and keep old ones.

I didn't try with another theme because I don't want to break the site to be honest, but I've tried to do the same on another website with GP and I have the same issue.

Hi there,

Yeah the stylesheet for comments area isn't loading when the comments are disabled.
https://github.com/tomusborne/generatepress/blob/7b35168f546f83a7abb098a8da3bc0674d49ddeb/inc/general.php#L22

the comments_open() within the logic for enqueuing the comments is the culprit.

But we should be able to manually enqueue the comments stylesheet back.

try this PHP snippet:

add_action( 'wp_enqueue_scripts', 'manual_comments_style_enqueue' );

function manual_comments_style_enqueue(){
$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' );
}

Here's how to add PHP: https://docs.generatepress.com/article/adding-php/

Hi Elvin,

Thank you for your help.

Apparently there's an issue on line 6 in your code https://imgur.com/a/1Pnbfcc

Any idea?

Thank you in advance

My code has 7 lines.

You missed the closing bracket }.

You are right, sorry :)

And it worked!

Thanks

No problem. Glad you got it sorted. :D

This archived topic is closed to new replies.