I want to add a page of content (a readme file) in the WordPress admin, I can’t seem to find how to do this in the codex – can anyone point me in the right direction? It will literally just be a simple page with a few paragraphs of content.
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
You need just two steps:
- Hook into the action
admin_menu, register the page with a callback function to print the content. - In your callback function load the file from
plugin_dir_path( __FILE__ ) . "included.html".
Demo code:
add_action( 'admin_menu', 'wpse_91693_register' );
function wpse_91693_register()
{
add_menu_page(
'Include Text', // page title
'Include Text', // menu title
'manage_options', // capability
'include-text', // menu slug
'wpse_91693_render' // callback function
);
}
function wpse_91693_render()
{
global $title;
print '<div class="wrap">';
print "<h1>$title</h1>";
$file = plugin_dir_path( __FILE__ ) . "included.html";
if ( file_exists( $file ) )
require $file;
print "<p class='description'>Included from <code>$file</code></p>";
print '</div>';
}
I added an example to my demo plugin T5 Admin Menu Demo to show how to do this in a sub menu and in a OOP style.
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0