I am trying to add a class to each row in a WordPress custom post type list page, e.g. to add a class based on value of meta field for each post on backend:
For example: I have a feature âcall enable/disableâ â if the post is disabled (i.e. only viewable by certain user), the whole row should have a certain background color.
So I am looking for a solution to add a CSS class based upon meta field value.
I’ll leave you with the material to mash this up.
For one, inspect the post classes,
We can change them with:
To print CSS, use:
This example looks for
?color=hexval
in the URL:You’ll get your meta data with the
$postID
in the filterpost_class
.Just in case brasofilo´s example gives you Missing argument warning, you can use the filter in the old way:
Then you have to define the function. In this example, I give each row a class with the ID of the post:
functions.php
admin.css