0

I want to add some content, in the top or bottom of the wordpress edit.php page for a custom post type. What is the right filter or way to do this ?

2
1

The action load-edit.php is not needed. The answer on Stack Overflow is based on this WPSE answer: How do you create a custom edit.php / edit pages page that uses pre_get_posts, that's why it was encapsulated inside load-PAGE action.

On the screen edit.php we don't have any action hooks to insert content. We can only use the filter views_edit-POST_TYPE to do something there. With jQuery we can adjust the position on screen.

add_filter( 'views_edit-POST_TYPE', function($views){
    echo '<h2 style="display:none;" id="my-element">My Custom HTML</h2>';
    echo "<script>
        jQuery(document).ready(function($){
            $('#my-element').detach().insertBefore('#ajax-response').fadeIn();
        });
        </script>";
    return $views;
});

Without jQuery it prints on position 1, and on position 2 using it.

-1

Try following these lines to add html content to edit.php:

<?php
# Called only in /wp-admin/edit.php pages
add_action( 'load-edit.php', function() {
  add_filter( 'views_edit-talk', 'talk_tabs' ); // talk is my custom post type
});

# echo the tabs
function talk_tabs() {
 echo '
  <h2 class="nav-tab-wrapper">
    <a class="nav-tab" href="admin.php?page=guests">Profiles</a>
    <a class="nav-tab nav-tab-active" href="edit.php?post_type=talk">Talks</a>
    <a class="nav-tab" href="edit.php?post_type=offer">Offers</a>
  </h2>
 ';
}
?>

Source: Stack Overflow - Add content to edit.php

3
  • But I dont wanna create new tabs
    – Amirition
    Jan 26 '19 at 12:59
  • Why don't you just put a link as comment to the original answer you have copied paste it from, you not even giving credits to that user on stackoverflow!
    – Charles
    Jan 27 '19 at 1:56
  • I am not just putting a link as a comment, as most of the users prefer the exact part of the solution in the answer. I have seen numerous times users are requesting the others to do that. However, I will include the link to the original answer from now. Jan 27 '19 at 11:11

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.