How to add custom widget above admin_footer

What I am trying to accomplish is placing custom widget on an admin page (edit.php). I tried using these two functions:

Places custom html right below < body > (above all page content)

Read More
add_action( 'load-edit.php', 'your_function' );
function your_function() {
    include( plugin_dir_path( __FILE__ ) . 'quickpost/quickpost.php');
}

Places custom html below the < footer >

add_action('admin_footer', 'post_add_quickpost');
function post_add_quickpost() {
    include( plugin_dir_path( __FILE__ ) . 'quickpost/quickpost.php');
}

Here is were I am trying to place the widget, just above the posts table on the edit.php page. http://i.imgur.com/QKHkEqs.jpg

Is there a way I can specify where to place the code? I would prefer to work with the ‘load-edit.php’ action, but if that is not possible – it is okay with me. Thanks!

Related posts

Leave a Reply

2 comments

  1. As far as I know you have 2 options.

    1. Using admin_footer or load-edit.php and position with absolute or fixed, or use JavaScript.

    2. If you creating a completely new posts screen (not a default posts, pages, etc), you can extend WP_List_Table class, specifically the extra_tablenav function.

    For example:

    class My_Custom_Table extends WP_List_Table {
    
        function extra_tablenav( $which ) {
    
            if ( $which == "top" ){
                //The code that goes before the table is here
                echo "Hello, I'm before the table";
               }
            if ( $which == "bottom" ){
                //The code that goes after the table is there
                echo "Hi, I'm after the table";
               }
          }
    }
    

    As far as I can tell, extending this class can only work on a custom admin page, and not the current existing ones, as there are no hooks available. You can read more about it here: http://codex.wordpress.org/Class_Reference/WP_List_Table

  2. I think that add_action( 'load-edit.php', 'your_function' ); is the correct way to do it, since it’s the only admin action designed to be fired only on a specific page. I would just style my metabox so that it’s absolutely positioned at the bottom of the posts list.

    You could also look at some other available actions available during an admin page load. If you find one that’s more appropriate, you could use a basic page check to load your plugin on only the desired page, something like:

    add_action( 'some-admin-action', 'your_function' );
    function your_function() {
         global $pagenow;
         if (is_admin() && $pagenow=='edit.php')
               include( plugin_dir_path( __FILE__ ) . 'quickpost/quickpost.php');
    }