Create a clickable name in WP_List_Table for Plugin Admin

I’ve been developing a plugin where I wanted to create a table, styled and working just like WordPress’s native Post/Page tables.

Following the guide below, I was able to create the table and load my database. The only thing I cannot figure out to do is how to make one of the row contents “clickable”.

WP_List_Table – a step by step guide

IE – making the “name” column clickable. I have the “edit, delete” buttons below the name, but that is not enough.

Any and all advice would be greatly appreciated. I looked at another plugin to see how they did this, and it looked like they broke the table apart and hardcoded the html for the table. I hope I don’t have to do this.

EDIT:

clickable, linked, name

The name of the post, Hello world!, as you can see, is a link / clickable.

SOLUTION

to make this work, I had to remove my custom column functions, which included my row actions. Turns out, you can simply call the row actions div! Here is the function that helped me, thanks to the Milo.

function single_row_columns($item) {
       list($columns, $hidden) = $this->get_column_info();
            foreach ($columns as $column_name => $column_display_name) {
                   $class = "class="$column_name column-$column_name"";

                   $style="";
                   if (in_array($column_name, $hidden))
                         $style=" style="display:none;"";

                   $attributes = "$class$style";

                   if ('cb' == $column_name) {
                   echo  "<td $attributes>";
                   echo '<input type="checkbox" name="id[]" value="%s" />', $item['ID'];
                   echo "</td>";
                        }
               elseif ('galname' == $column_name) {
               echo "<td $attributes>";
               echo '<a href="#">', $item['galname'];
               echo "</a>";

                   echo "<div class="row-actions"><span class="edit">";
           echo sprintf('<a href="?page=%s&action=%s&gid=%s">Edit</a>',$_REQUEST['page'],'edit',$item['id']);
                   echo "</span> | <span class="trash">";
           echo sprintf('<a href="?page=%s&action=%s&gid=%s">Delete</a>',$_REQUEST['page'],'delete',$item['id']);
           echo "</span></div></td>";
                                                    }
            else {
                echo "<td $attributes>";
                echo $this->column_default( $item, $column_name );
                echo "</td>";
            } } } 

Thanks so much!
Jacob

2 Answers
2

The WP_List_Table class ultimately uses the single_row_columns method to output each table cell. If we look at that method, we’ll see this part:

...
elseif ( method_exists( $this, 'column_' . $column_name ) ) {
    echo "<td $attributes>";
    echo call_user_func( array( &$this, 'column_' . $column_name ), $item );
    echo "</td>";
}
...

Add a method to your class for the column you want to add additional functionality / formatting to and name it 'column_' . $column_name, then output any additional markup you need wrapping the item content.

Leave a Comment