Search code examples
wordpresspluginscustom-post-typetheme-development

How to add content in admin page / edit.php on my custom post type


I create a custom post type. My custom post type link like: http://localhost/le/wp-admin/edit.php?post_type=pdfviewer

In my custom post edit.php page I want to display some content. Now how to add content here. Please see the image below for better understand. Thank you.

admin page / edit.php


Solution

  • To target edit.php, you can use the all_admin_notices action wrapped inside the load-edit.php action:

    add_action('load-edit.php', function () {
    
        $screen = get_current_screen();
    
        // Only edit for your custom post type screen
        // Here edit-YourPostType
        if ('edit-pdfviewer' === $screen->id) {
            add_action('all_admin_notices', function () {
                echo '<p>Your custom content here!</p>';
            });
        }
    });