I want to set a different color border for product drafts and published products in my WordPress backend page.

If there is a drafted product in my WordPress product listing page then it should have a red background color and if there is a published product available then it should have a green background color.

  • Sorry, I have misread your question. You need backend, my solution is for front end – Pieter Goosen Jan 21 '15 at 13:05

You can actually achieve this using simple CSS. If you look at the HTML you can see that each row has some classes:

 <tr class="post-1349 type-page status-draft hentry alternate iedit author-self level-0" id="post-1349">

There you can see that there actually is a class that indicates a draft: status-draft

So now by simply adding an admin style you can easily style drafts. Just create a css file in wp-content/themes/your-theme-name/admin-style.css and add this:

.status-draft {
  background-color: red;

...or published posts:

.status-publish {
  background-color: green;

Now you need to add this to your wp-content/themes/your-theme-name/functions.php file:

add_action( 'admin_enqueue_scripts', 'wpse_175526_load_admin_style' );
function wpse_175526_load_admin_style() {
    wp_enqueue_style( 'wpse_175526_admin_css', get_template_directory_uri() . '/admin-style.css', false, '1.0.0' );

For details on how you add an admin style please head over to this answer: adding custom stylesheet to wp-admin

  • Have you read the link I posted concerning how to add custom admin styles? – kraftner Jan 21 '15 at 12:59
  • yes...i read those article and also try it but I'm failed to getting success. will you please tell me actually in which file i have to write this php code? – Yogesh Chalodiya Jan 21 '15 at 13:35
  • Yogesh I added some more details. – kraftner Jan 21 '15 at 13:40
  • add_action( 'admin_enqueue_scripts', 'wpse_175537_load_admin_style' ); in this line what is the meaning of "wpse_175537_load_admin_style". – Yogesh Chalodiya Jan 21 '15 at 13:46
  • there are many functions.php file. so in which folder locations i have to write this code for functions.php? – Yogesh Chalodiya Jan 21 '15 at 13:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.