問題描述
我在這裏發現了 WPSE,你可以在頁面中的 add content before post title 和自定義的帖子類型頁面
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>';
});
}
});
哪個工作在我的預訂自定義帖子類型。但我想知道是否可以在標題後輸出內容,但是在使用自定義帖子類型之前可以輸出內容?
最佳解決方案
您可以嘗試在 WP_List_Table 類中的”hijack” 以下過濾器:
/**
* 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 );
例子
對於 edit-post 屏幕,過濾器為 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;
} );
這將顯示為:
次佳解決方案
你可以用 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>';
} );
參考文獻
注:本文內容整合自 Google/Baidu/Bing 輔助翻譯的英文資料結果。如果您對結果不滿意,可以加入我們改善翻譯效果:薇曉朵技術論壇。

