When you want to add an options page in WordPress, you need to use function add_options_page. This example will create one page containing a simple sting:
add_action( 'admin_menu', 'my_menu' );
function my_menu() {
add_options_page(
'Menu Title',
'Page Title',
'manage_options',
'page-slug',
'callback_fn'
);
}
function callback_fn()
{
echo "Some text";
}
First part of the example adds an action to call a function for creating our menu page. This action is called admin_menu. In action callback we add function add_options_page. This function has 5 parameters:
- Title in WordPress menu
- Page title (Title display by browser)
- User capabilities (we use “manage_option“)
- Page slug (URL in browser)
- Callback function of our page (this function is called, when the page is displayed, it contains all of the source code for the page and in our case is just a simple string)
Was this article helpful?
If you have any suggestions or questions, please leave a comment below.
Leave A Comment