Wordpress, add a custom button on the post type list page

I am trying to add a custom button on top of a message type page, for example this image enter image description here

Is there any filter or action that I can use to add a custom button?

thanks

+5
source share
3 answers

I found a way to do this, but I am not very happy with this procedure. Please add your answer if you find a better way. Average time, this can be useful.

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

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

 /** * 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='doc_popup' class='add-new-h2'>Import</a>"); }); </script> <?php } 
+8
source

We dig into the main WordPress code, I did not find a single hook or any filter for this button, you can also see this code from line no 281 to line number 288 . But you can add here according to this filter .

 add_filter('views_edit-post','my_filter'); add_filter('views_edit-page','my_filter'); function my_filter($views){ $views['import'] = '<a href="#" class="primary">Import</a>'; return $views; } 

Hope this helps you.

+3
source

The accepted answer, unfortunately, remains the only thing that works.

But since the admin header has changed since the response, the correct script should be as follows:

 jQuery(jQuery(".wrap .page-title-action")[0]).after('<a href="#" class="page-title-action">Import</a>'); 
0
source

All Articles