I added a new menu item for my plugin like this:
add_menu_page(
'Control Panel',
'My Plugin',
'manage_options',
'control-panel',
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?
From the codex page:
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