Hook into WordPress custom post type and change the row background color - Hack The Tech - Latest News related to Computer and Technology

Hack The Tech - Latest News related to Computer and Technology

Get Daily Latest News related to Computer and Technology and hack the world.

Sunday, July 30, 2023

Hook into WordPress custom post type and change the row background color

So I need some help and I can't seem to figure this out, but in the backend of WordPress I have a custom post type called "wp_events".

In there, I have "Scheduled", "Draft" and "Published" posts.

So let's take for example this:
enter image description here

If the post is "Scheduled", I would like to have the whole row as a lightgreen background color.

I tried the following code:

// Add custom column CSS on wp_events admin 
function wp_events_custom_css($column) {

  // Only target status column
  if( $column == 'status') {

    echo '<style>
       .status-scheduled {
         background: lightgreen!important;
       }
    </style>';

  }

}

// Hook into column rendering
add_action('manage_wp_events_posts_custom_column', 'wp_events_custom_css', 10, 2);

But I am unable to target it properly, so I am looking to see if someone might be able to assist me or know an easier way.

I tried the above code and was expecting the row to turn a lightgreen color.



source https://stackoverflow.com/questions/76794949/hook-into-wordpress-custom-post-type-and-change-the-row-background-color

No comments:

Post a Comment