How can I add a button to a posts -page. (In this case a custom post type).
I’d like to place it next to, or near, the “Add new” button, to import content from a web service.
2 Answers
You can add button via add_meta_box function.
function add_your_meta_box(){
add_meta_box('your-metabox-id', 'Title', 'function_of_metabox', 'custom_post_type', 'side', 'high');}
add_action('add_meta_boxes', 'add_your_meta_box');
function function_of_metabox()
{?>
<input type="submit" class="button button-primary button-large" value="Add New" id="add-new"/>
<?php }
if you add to multiple post type, you should use foreach loop.
function add_your_meta_box(){
$types = array("post","page","custom_post_type");
foreach($types as $type){
add_meta_box('your-metabox-id', 'Title', 'function_of_metabox', $type, 'side', 'high');}
}
add_action('add_meta_boxes', 'add_your_meta_box');