Support » Fixing WordPress » assigning classes to tags: How?

  • Hi all,

    I need to apply 2 classes to 2 tags but I am unsure how.

    ‘<p class=”posted”>
    <?php smart_comments_popup_link(‘Want to reply?’, ‘1 Comment’, ‘% Comments’); ?>
    <?php _e(“Filed under:”); ?> <?php the_category(‘,’) ?>’

    I would like to apply a class to the a href of the tags smart comments and the category.

    I am not 100% sure how I do this though. Can youi help please?

    Thanks a bunch

Viewing 15 replies - 1 through 15 (of 16 total)
  • Mark (podz)


    Support Maven

    .posted {

    That will turn the text red – add whatever else you wish.
    That okay ?

    Ah sorry Podz – I mean’t I want to assign a class to the ‘category’ tag called ‘class 1’ for example and to the ‘comments popup’ ‘class 2’. and then remove the ‘posted’ tag

    Can I do that? I thought I could do that in the () of the corresponding tags but I am unsure how.

    Thank you

    Mark (podz)


    Support Maven

    ‘<div class=”class1″>
    <?php smart_comments_popup_link(‘Want to reply?’, ‘1 Comment’, ‘% Comments’); ?></div>
    <div class=”class2″>
    <?php _e(“Filed under:”); ?> <?php the_category(‘,’) ?>

    .class1 {
    color: #ff0000;

    .class2 {
    color: #0000ff;

    That would work .. but linebreaks may happen..

    Thanks for that Podz 🙂

    So I guess I can’t do it inline then like this:

    Want to reply?

    Sorry to be a pain but I would like it like this if possible.

    Sorry and thanks so far 🙂

    ‘a href=”” class=”classname_here”>Want to reply?</a’

    Use the <span> tag (in place of <div>) for inline stuff.

    Hi Kafkaesqui,

    Where would I put it in ‘<?php smart_comments_popup_link(‘Want to reply?’, ‘1 Comment’, ‘% Comments’); ?>’ ?

    Thanks 🙂

    Just replace the div that podz used in his example:

    <span class="class1">
    <?php smart_comments_popup_link('Want to reply?', '1 Comment', '% Comments'); ?></span>

    Hi there,

    sorry it’s still not what I am after – I want to put the class withing the a href tag of smart_comments_popup_link

    I guess that can’t be done unless I hard code. What file deals with this code?


    I suspect that the real issue here is that you want to restyle the link. Further presentational markup would not normally be necessary to do that. If you have a url we can take a stab at the selector.

    “I want to put the class withing the a href tag of smart_comments_popup_link. I guess that can’t be done unless I hard code.”

    Unfortunately that’s correct. smart_comments_popup_link() is from a hack or plugin, depending on the version you’ve implemented, but it uses comments_popup_link() to generate the link, which is a function found in:


    For 1.5 it should be around line 90 in that file. Look for:

    echo '<a href="';

    You can insert your class attribute there.

    Note: Back up source files before editing them, and comment your changes for future reference.

    So, would a plug for one of my plugins work here?

    This should let you make your additions without editing the source. However, it does require modifying your templates, i.e.:

    <?php add_link_attr('smart_comments_popup_link', 'Want to reply?, 1 Comment, % Comments', 'class="class1"'); ?>

    Hey Kafkaesqui,

    Thats pretty cool 🙂

    I just don’t like to keep surround elements with spans on unnescasary divs.

    I will try this out and get back to you 🙂

    I think that might just do it 🙂

    I am not quite sure how to write the code for this one though:

    ‘<?php _e(“Filed under:”); ?>’

    Thank you for all your assistance so far 🙂

    _e() is a localization function, and all it does it display the text it’s holding as an argument (or translate and display it if you’ve localized WordPress into another language). If it needs styling beyond the div or p it’s in, I think you’re best off just sticking it in a span. I know, but I think my plugin would be overkill for wrapping that function, especially since you’ll still need to place a div or span around it to style the text.

Viewing 15 replies - 1 through 15 (of 16 total)
  • The topic ‘assigning classes to tags: How?’ is closed to new replies.