Last active
November 28, 2017 20:29
-
-
Save thierrypigot/23b307548e8c31ee36a8522e1c19b0f6 to your computer and use it in GitHub Desktop.
Add WordPress admin menu + submenu
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class WeAreWP { | |
function __construct() { | |
} | |
function init() { | |
add_action( 'admin_menu', array( $this, 'wearewp_plugin_top_menu' ) ); | |
} | |
function wearewp_plugin_top_menu(){ | |
add_menu_page( 'WeAre[WP]', 'WeAre[WP]', 'manage_options', 'wearewp', array( $this, 'wearewp_render_plugin_page' ) ); | |
add_submenu_page( 'wearewp', 'About', 'About', 'manage_options', 'wearewp-about', array( $this, 'wearewp_render_about_page' ) ); | |
} | |
function wearewp_render_plugin_page(){ | |
?> | |
<div class='wrap'> | |
<h2>Plugin page</h2> | |
</div> | |
<?php | |
} | |
function wearewp_render_about_page(){ | |
?> | |
<div class='wrap'> | |
<h2>About page</h2> | |
</div> | |
<?php | |
} | |
} | |
$wearewp = new WeAreWP(); | |
$wearewp->init(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
add_action('admin_menu','wearewp_plugin_top_menu'); | |
function wearewp_plugin_top_menu(){ | |
add_menu_page( 'WeAre[WP]', 'WeAre[WP]', 'manage_options', 'wearewp', 'wearewp_render_plugin_page' ); | |
add_submenu_page( 'wearewp', 'About', 'About', 'manage_options', 'wearewp-about', 'wearewp_render_about_page'); | |
} | |
function wearewp_render_plugin_page(){ | |
?> | |
<div class='wrap'> | |
<h2>Plugin page</h2> | |
</div> | |
<?php | |
} | |
function wearewp_render_about_page(){ | |
?> | |
<div class='wrap'> | |
<h2>About page</h2> | |
</div> | |
<?php | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Cool !
Merci pour la function !