1

I would like another "Add post" button in the admin except I am going to call it "Add voucher". It will run specific plugins that add post will not. However that is irrelivant, all I need to know it how to add another add post button with the same features.

4

Unfortunately this isn't possible (without a slight hack)- since there are no hooks provided (see for example the edit.php page).

A quick and easy hack is to use JavaScript to add the link after the usual 'Add New' link. Here I've used the admin_print_footer_scripts hook (on 'post', or 'edit-post' screens) to print the JavaScript. Note that you must alter this to work for other post types.

add_action('admin_print_footer_scripts','wpse57033_add_new_voucher_link');
function wpse57033_add_new_voucher_link(){
    $screen = get_current_screen();
    if( $screen->id == 'edit-post' || $screen->id == 'post' ){
        ?>
            <script>
            jQuery('.wrap h2 .add-new-h2').after('<a href="" class="add-new-h2">Add New Voucher</a>');
            </script>
        <?php
    }
}
  • @RuturaajPatki asked why some people check $variable == 'value' and others 'value'== $variable. I've been lazy in this answer, but the latter is best practise (see this for an explanation). Otherwise they are the same. – Stephen Harris Jul 1 '12 at 14:29
  • $screen is an object, when making comparisons, it can help to force (string) type in the evaluation. Example Code: if( ( (string)$screen->id == 'user-edit' || (string)$screen->id == 'users' ) && ( current_user_can('editor') || current_user_can('administrator') ) ){ // do stuff } Screen Type Reference: codex.wordpress.org/Plugin_API/Admin_Screen_Reference – roberthuttinger Mar 16 '18 at 15:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.