WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I added a new menu item for my plugin like this:

  'Control Panel',
  'My Plugin',
  array($this, 'control_panel_page'),
  plugins_url('/images/menu_icon.png', __FILE__)

public function control_panel_page() {
  // My HTML goes here

However, I feel uncomfortable with the fact that all my HTML resides in PHP function (control_panel_page).

Is there an option/hack to point to HTML file rather than PHP function?

share|improve this question
in your public function just php include() the html file.... – Barry Carlyon Aug 9 '12 at 12:23
up vote 2 down vote accepted

From the codex page:

$menu_slug (string) (required) The slug name to refer to this menu by (should be unique for this menu). Prior to Version 3.0 this was called the file (or handle) parameter. If the function parameter is omitted, the menu_slug should be the PHP file that handles the display of the menu page content. Default: None

share|improve this answer
This leaves us with an incorrect path - mysite.com/wp-admin/included_file.php – BenRacicot Feb 21 '14 at 19:28

You can use the file_get_contents() function to load a file into a string and write it's contents.

It doesn't exactly replaces the function with the file, but if your point in question is to have separate PHP file for the plugin logic, and another for the "HTML" page, than this should help.

The following code is enough to response the content of a "HTML" or any other text file rather than echoing from the PHP code. Plugin consists of two files:

  • file.php
  • hello.html


Plugin Name: HTML Include Plugin
Version: 1.0

    // register menu item
    add_action('admin_menu', 'admin_menu_item');    

function admin_menu_item()
    // add menu item
    add_menu_page('HTML Include Plugin', 'HTML Include Plugin', 'manage_options', 'html-include-plugin', 'admin_page');

function admin_page()
    // write the contents of the HTML file
    $file = file_get_contents('hello.html', FILE_USE_INCLUDE_PATH);
    if($file == false)
        echo 'file not found';
        echo $file;



    This is a sample HTML content, but this can be any kind of text file...
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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