Wordpress:将内容添加到edit.php

时间:2013-02-10 05:09:28

标签: wordpress

enter image description here我试图找出我可以用什么动作挂钩/过滤器在admin“edit.php”页面上插入内容(我想在'posts'表上方放置一些链接) ?我找到了“edit_form_after_title”和“edit_form_after_editor”(这些正是我想要做的,但它们适用于posts.php,而不是edit.php)。

2 个答案:

答案 0 :(得分:4)

借助这个答案:https://wordpress.stackexchange.com/a/115164/59816

我想出了这个:



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

它看起来像这样:

enter image description here

希望这有助于某人。

答案 1 :(得分:2)

如果你只想添加到帖子标题链接,你可以做这样的事情

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

但是,听起来你不想在标题链接中添加文字。

要在标题之后和操作链接之前添加html,您可以这样做

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

页面编辑屏幕也有page_row_actionspost_row_actions仅适用于帖子)

至于在标题之前添加内容,我没有看到钩子/过滤器来做到这一点。如果您想自己寻找,请参见wp-admin/class-wp-posts-list-table.php第463行function single_row