Title: Define class and id using php
Last modified: August 18, 2016

---

# Define class and id using php

 *  [Alex Cragg](https://wordpress.org/support/users/epicalex/)
 * (@epicalex)
 * [19 years, 1 month ago](https://wordpress.org/support/topic/define-class-and-id-using-php/)
 * i recently altered my comments.php to highlight alternate posts different colours,
   and also when i wrote a comment, to highlight that a different colour too. I 
   used some code i found in the support forum for the alternate highlighting, and
   the [Author Highlight](http://wordpress.org/extend/plugins/author-highlight/)
   plugin for highlighting my comments.
 * to achieve this, i gave the li tag a class and an id, i created the li class 
   and id like this
    `<li class="<?php echo $oddcomment; ?>" id="<?php author_highlight();?
   >">`
 * where the $oddcomment variables had been defined before.
 * what i now want to know is, is it possible to create a plugin that would define
   the class and the id of the li tag in one go, as opposed to two sections.
    so
   you’d end up with something like this `<li <?php admin_alt_highlight(); ?>` which
   would create an output like `<li class="alt" id="author">`
 * any pointers much appreciated

Viewing 4 replies - 1 through 4 (of 4 total)

 *  Thread Starter [Alex Cragg](https://wordpress.org/support/users/epicalex/)
 * (@epicalex)
 * [19 years, 1 month ago](https://wordpress.org/support/topic/define-class-and-id-using-php/#post-556515)
 * anyone know if this sort of stuff is possible?
 *  [Pizdin Dim](https://wordpress.org/support/users/pizdin_dim/)
 * (@pizdin_dim)
 * [19 years, 1 month ago](https://wordpress.org/support/topic/define-class-and-id-using-php/#post-556517)
 * You need to keep in mind that in CSS and “id” attribute **must be unique**, so
   this is actually **invalid**, unless there’s only **one comment** made by the
   author:
 * `<li class="alt" id="author">`
 * I’m assuming from what you’re saying that you want to be able to somehow highlight
   any comments by the author of the post. If so, the above is only good if the 
   author leaves only one comment, which is impractical.
 * Perhaps a better solutions is to use multiple classes (instead of a class and
   an id) instead.
 *  Thread Starter [Alex Cragg](https://wordpress.org/support/users/epicalex/)
 * (@epicalex)
 * [19 years, 1 month ago](https://wordpress.org/support/topic/define-class-and-id-using-php/#post-556518)
 * [@pizdin_dim](https://wordpress.org/support/users/pizdin_dim/) – i realized that
   after i posted this topic(thanks to the validator), and i changed it straight
   away on my current theme.
 * mod look added for jmcpherson421 posts…pretty weird posts IMO.
 * so im not really any closer…
 * ill phrase it differently,
 * i would like to know how to generate 2 class out puts in 1 php call.
 *  [Pizdin Dim](https://wordpress.org/support/users/pizdin_dim/)
 * (@pizdin_dim)
 * [19 years, 1 month ago](https://wordpress.org/support/topic/define-class-and-id-using-php/#post-556520)
 * Instead of `<li class="alt" id="author">` use `<li class="alt author">`

Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘Define class and id using php’ is closed to new replies.

## Tags

 * [Comments](https://wordpress.org/support/topic-tag/comments/)
 * [php](https://wordpress.org/support/topic-tag/php/)

 * In: [Developing with WordPress](https://wordpress.org/support/forum/wp-advanced/)
 * 4 replies
 * 2 participants
 * Last reply from: [Pizdin Dim](https://wordpress.org/support/users/pizdin_dim/)
 * Last activity: [19 years, 1 month ago](https://wordpress.org/support/topic/define-class-and-id-using-php/#post-556520)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
