Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Wordpress: Add content to edit.php

Tags:

wordpress

enter image description hereI'm trying to find out what action hook/filter I can use to insert content on the admin "edit.php" page (i want to place a few links above the 'posts' table)? I've found "edit_form_after_title" and "edit_form_after_editor" (these do exactly what I want to do, but they are for posts.php, not edit.php).

like image 679
execv Avatar asked Dec 27 '22 09:12

execv


2 Answers

With the help of this answer: How do you create a custom edit.php / edit pages page

I came up with this:

<?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>
 ';
}
?>

And it looks like this:

like image 198
Carole Magouirk Avatar answered Dec 28 '22 23:12

Carole Magouirk


If you just wanted to add to the post title link you could do something like this

if (is_admin()) {
    add_filter('the_title', function($title) {
        return $before_title . $title . $after_title;
    });
}

however, it doesn't sound like you want to add text to the title link.

To add html after the title and before the actions links, you could do like this

if (is_admin()) {
    add_filter('post_row_actions', function($args) {
        // echo your custom content here
        return $args; // and dont forget to return the actions
    });
}

There is also page_row_actions for the page edit screen (post_row_actions is only for posts)

As far as adding stuff before the title, I don't see a hook/filter to do that. See wp-admin/class-wp-posts-list-table.php line 463 function single_row if you want to look for yourself.

like image 29
Rob Avatar answered Dec 28 '22 23:12

Rob