How do I add a custom button to my “edit” list? ( edit.php?post_type= ) beside “Add New”

I have a custom post type for a plugin I’m creating and the label for the “add an item” type of button (at the top of the list page) needs a partner-button that says “import” and one that says “export” so that I can (after a brief confirmation dialogue) allow my client to push and pull the records with a JSON file that is already all set up; I just need them to be able to trigger it and I can’t figure out how to add buttons to the list page.

A screenshot of the button on the edit list

So I need to add “Import” and “Export” after the “Add an Entry” button.

Any help is greatly appreciated.

2 Answers
2

I found a way to get it done but I am not very happy with this procedure. Please add your answer if you find better way. Mean while, this might be of help.

add_action('admin_head-edit.php','addCustomImportButton'));

I only need this on edit page, so I am using admin_head-edit.php action, but you can use admin_head or some other (not very specific requirement)

/**
 * Adds "Import" button on module list page
 */
public function addCustomImportButton()
{
    global $current_screen;

    // Not our post type, exit earlier
    // You can remove this if condition if you don't have any specific post type to restrict to. 
    if ('module' != $current_screen->post_type) {
        return;
    }

    ?>
        <script type="text/javascript">
            jQuery(document).ready( function($)
            {
                jQuery(jQuery(".wrap h2")[0]).append("<a  id='aspose_doc_popup' class="add-new-h2">Import</a>");
            });
        </script>
    <?php
}

Leave a Comment