I am trying to add custom button on top of post type page like this image
Is there any filter or action I can use to add custom button there?
Thanks
Adding a button without using a plugin can be done in a few different ways. One way is to use the WordPress customizer. To do this, go to the Customizer and click on the Buttons tab. Here, you can add a new button by clicking on the Add new button button.
First, you need to create a new post or edit an existing one where you want to add a button. On your post edit screen, click on the '+' icon to add a New Block and select the Button block under the Layout Elements section. Simply click on the 'Add text…' area and enter your button text.
If you are using the class WP_Lists_table (and you should) then this is the right way to do it:
add_action('manage_posts_extra_tablenav', 'add_extra_button');
function add_extra_button($where)
{
global $post_type_object;
if ($post_type_object->name === 'shop_order') {
// Do something
}
}
Digging into WordPress core code i did not find any hook or any filter for that buttonm you can also see that code from line no 281 to line number 288 . But you can add your button 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 it helps you.
Unfortunately there is no hook called after showing the "Add New" button. The closest possible place to add anything without using javascript is below the title and "Add new" like this:
In my example I added a button to my custom post type "Event" using the hook "edit_form_top":
add_action('edit_form_top', 'add_custom_button');
function add_custom_button($id){
if ($post->post_type != 'event') return false;
echo('<button>Custom button</button>');
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With