Is there hook to place a button besides "add new". I'm trying to use it on a custom post type.

I'm currently using this code. I don't know if it's the proper way though.

    function custom_js_to_head() {
        jQuery("body.post-type-wpr_guest_suit .wrap h1").append('<a href="index.php?param=your-action" class="page-title-action">List View</a>');
add_action('admin_head', 'custom_js_to_head');

enter image description here


The 'proper' way would be to use add_action()

See: https://codex.wordpress.org/Plugin_API/Action_Reference

The closest hook for your need would be 'edit_form_top'

You could do something like this

function add_your_button(){
    echo '<a href="index.php?param=your-action" class="page-title-action">List View</a>';
add_action('edit_form_top', 'add_your_button');

That would achieve:

enter image description here

The catch is that there is a hr tag after the Add New so your new button is going to get pushed down the screen by the hr and also alerts eg Autosave alerts.

I'd suggest you use the magic of CSS to position your button absolutely.

Something like:

.custom-class-for-your-button {
  position: absolute;
  top: 1.6em;
  left: 14em;

Though make sure you provide CSS to support the full range of screen sizes your editors are likely to edit the site with.

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.