5

I found here on WPSE that you can add content before post title in the post page, and in custom post type pages

    add_action( 'load-edit.php', function(){

       $screen = get_current_screen();

        // Only edit post screen:
       if( 'edit-reservation' === $screen->id )
       {
            // Before:
            add_action( 'all_admin_notices', function(){
                echo '<p>Greetings from <strong>all_admin_notices</strong>!</p>';
            });

        }
    });

Which works in my reservation custom post type. But I'm wondering if it's possible to output content after the title, but before table with custom post types?

enter image description here

2 Answers 2

9

You could try to "hijack" the following filter in the WP_List_Table class:

/**
 * Filter the list of available list table views.
 *
 * The dynamic portion of the hook name, `$this->screen->id`, refers
 * to the ID of the current screen, usually a string.
 *
 * @since 3.5.0
 *
 * @param array $views An array of available list table views.
 */
 $views = apply_filters( "views_{$this->screen->id}", $views );

Example

For the edit-post screen, the filter is views_edit-post:

/**
 * Display HTML after the 'Posts' title
 * where we target the 'edit-post' screen
 */
add_filter( 'views_edit-post', function( $views )
{
    echo '<p>Greetings from <strong>views_edit-post</strong></p>';

    return $views;
} );

and this will display as:

greetings

0
2

You can do it with JavaScript.

add_action( 'all_admin_notices', function(){
    echo '<script>jQuery(document).ready(function($) {  $( "<p>Greetings from <strong>all_admin_notices</strong>!</p>" ).insertAfter( ".subsubsub" );});</script>';
} );
5
  • I was aiming for the non javascript-able solution :\
    – dingo_d
    Commented Feb 9, 2016 at 20:07
  • Why? Wordpress depends heavily on jQuery and JavaScript. insertAfter is supported by every known browser back to the beginning of time. You would be hard pressed to find a more reliable solution, imho. Commented Feb 9, 2016 at 20:34
  • Because, when developing a plugin, I like to do most of the stuf with php (as possible). So if there is a hook to use, why not? :)
    – dingo_d
    Commented Feb 9, 2016 at 21:28
  • 1
    Fair enough. I also prefer to get things done on the server side. Commented Feb 9, 2016 at 21:30
  • And.. there clearly is not a hook, looking at the accepted answer - this is a reliable hack!
    – Q Studio
    Commented Mar 14, 2022 at 13:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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