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.
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It only takes a minute to sign up.
Sign up to join this communityHow 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.
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');
Like this:
function custom_js_to_head() {
?>
<script>
jQuery(function(){
jQuery("body.post-type-YOUR-CUSTOM-POST-TYPE .wrap h1").append('<a href="index.php?param=your-action" class="page-title-action">Import from ...</a>');
});
</script>
<?php
}
add_action('admin_head', 'custom_js_to_head');
That code (pasted to functions.php) will dynamically add new link tag after "Add new" link.