0

I would like to add a button next to the column name in e.g. edit.php admin screen. I have added a printsreen showing where I would like the button to go.. I have searched for available hooks but there appears to be none.

Any ideas anyone?

Thanks a lot!

enter image description here

  • @Harrrymandilas I have answered bellow and it should works – Firefog Nov 22 '15 at 6:40
0

You are looking code to add a column next to short link. It's pretty much simple. There are two things here. You can add it for specific post type or common to all the post types you have.

  // add a thumbnail column to the edit posts screen
  function kv_post_thumbnail_column($cols) {
       $cols['thumbnail'] = __('Thumbnail', '1stopwebsolution');
       return $cols;
   }
  add_filter('manage_posts_columns', 'kv_post_thumbnail_column');


   // go get the attached images for   the logo and thumbnail columns
    function   kv_thumbnail_value($column_name, $post_id) {

        if (('thumbnail' == $column_name) || ('logo' == $column_name)) {

             if (has_post_thumbnail($post_id)) echo get_the_post_thumbnail($post_id, array( 71, 61));

            }
     }
 add_action('manage_posts_custom_column', 'kv_thumbnail_value', 10, 2); 

This will add a Thumbnail column next at last of all the post type's listing table.

You can create post type specific one with the following link. Read more and get it.

https://codex.wordpress.org/Plugin_API/Action_Reference/manage_posts_custom_column

  • Thanks but I am afraid this is not what I asked for. I am OK with adding custom columns. My question was how could I add a button (or any other html code) next to the name of a column. Something similar to restrict_manage_posts, but within the column header div.. – harman Nov 22 '15 at 1:19
  • You can add it like this. ` $cols['thumbnail'] = '<button name=" test button " ></button>;`. But I am not sure whether this one works or not. – Kvvaradha Nov 22 '15 at 1:23
  • Yes this (your follow-up answer) was actually what I wanted to do.. Silly I did not think of it before asking. I thought i had at least tried that... Thanks for the help! – harman Nov 22 '15 at 10:52
0

I have tested add bellow code to your theme functions.php

  function firefog_post_edit_column($cols) {
       $cols['edit'] = __('Button', 'firefog');
       return $cols;
   }
  add_filter('manage_posts_columns', 'firefog_post_edit_column');

    function   firefog_post_edit_value($column_name, $post_id) {
        if ('edit' == $column_name) {
             echo '<button class="button">Button</button>';
            }
     }
 add_action('manage_posts_custom_column', 'firefog_post_edit_value', 10, 2); 2); 
  • This adds a button to all rows. What I wanted was to add a button just in the title of the column. The follow-up answer by Akelya sorted it out. – harman Nov 22 '15 at 10:50

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.