Francesca
Francesca

Reputation: 28148

Adding CSS class names to comments_popup_link in WordPress theme.

I'm currently trying to style up a Wordpress theme, I don't have the greatest PHP knowledge but it's going pretty good so far.

My one question is, how can I add classes and ID's to hook my CSS to? For example:

The code to generate the 'leave a comment' link on each post is:

<?php comments_popup_link('Leave a Comment', '1 Comment', '% Comments'); ?>

I want to style this, it displays out as a link, but obviously I can't change the CSS simply for every a tag in my main column. I need to add some sort of class to hook on to.

How do I do this?

<?php class="commentLnk" comments_popup_link('Leave a Comment', '1 Comment', '% Comments'); ?>

^ Guessing that isn't right at all.

Upvotes: 0

Views: 1332

Answers (2)

Reactgular
Reactgular

Reputation: 54771

You can add your own CSS style classes to the comments link.

comments_popup_link('Leave a Comment', '1 Comment', '% Comments', 'cssclass');

As explained in the WordPress API documentation for the commands_popup_link.

Upvotes: 3

Nick Coad
Nick Coad

Reputation: 3694

This will do the trick:

<span class="commentLnk"><?php comments_popup_link('Leave a Comment', '1 Comment', '% Comments'); ?></span>

Alternatively, the function also accepts a fourth parameter which will be used as the class:

<?php comments_popup_link('Leave a Comment', '1 Comment', '% Comments', 'commentLnk'); ?>

Upvotes: 4

Related Questions