add_action for admin admin menu code example

Example 1: To add a new Top-level menu to WordPress Administration, use the add_menu_page() function.

//////neha jaiswal///
<?php
add_action('admin_menu','wpac_register_menu_page');
function wpac_register_menu_page()
{
	add_menu_page('WPASsystem','WPAC Settings','manage_options','wpac-setting','wpac_settings_page_html','dashicons-admin-plugins',15);
}
function wpac_settings_page_html()
{		$content='';
	$content.="<h1>welocome</h1>";
	$content.='<form method="post">
	  <h1>Contact Us</h1>
        <div class="info">
          <input type="text" name="name" placeholder="Full name">
          <input type="text" name="email" placeholder="Email">
          <input type="text" name="number" placeholder="Phone number">
          <input type="text" name="Website" placeholder="Website">
        </div>
        <p>Message</p>
        <div>
          <textarea rows="4"></textarea>
        </div>
        <button type="submit" href="">Submit</button>
      </form>';
echo $content.='<button><a href="https://www.w3schools.com">absgfs</a></button>';
}
add_shortcode('wpac-setting','wpac_settings_page_html');
?>
/////////////// plz visit this site for more details //////
https://developer.wordpress.org/plugins/administration-menus/top-level-menus/

Example 2: how add administration menu in wordpress

<?php
/** Step 2 (from text above). */
add_action( 'admin_menu', 'my_menu' );
 
/** Step 1. */
function my_menu() {
    add_options_page(  //this code Add submenu page to the Settings main menu
        'My Options',
        'My Menu',       //this paramenter display menu option in administration setting 
        'manage_options',
        'my-unique-identifier',
        'my_options'
    );
}
 
/** Step 3. */
function my_options() {
    if ( !current_user_can( 'manage_options' ) ) {
        wp_die( __( 'You do not have sufficient permissions to access this page.' ) );
    }
    echo 'Here is where I output the HTML for my screen.';
    echo '</div><pre>';
}
?>

Tags:

Php Example