Wordpress Theme Development Tip#1
hi, From now on, I will start sharing tips on wp theme development. Add below code in your theme function.php
Remove some menu from admin menu in backend dashboard
function remove_admin_menu_items() { $remove_menu_items = [ __('Plugins'), __('Comments'), __('Posts'), __('Pages'), __('Tools'), __('Appearance') ]; global $menu; end ($menu); while (prev($menu)){ $item = explode(' ',$menu[key($menu)][0]); if(in_array($item[0] != NULL?$item[0]:"" , $remove_menu_items)){ unset($menu[key($menu)]);} } add_action('admin_menu', 'remove_admin_menu_items');
This code contain array of menu item that will remove Plugins, Comments, Posts, Pages, Tools & Appearance menu from the dashboard. This is good if you want to restrict the access from client.
Remove plugin menu item from admin backend dashboard
function wpeditor17_remove_plugin_admin_menu() { remove_menu_page('wpeditor_admin'); } add_action( 'admin_menu', 'wpeditor17_remove_plugin_admin_menu', 9999 );
This function are the same as above but specifically wrote for plugin's menu.
Add certain page in admin dashboard
function add_home_menu_page(){ add_menu_page( 'Home PAge', 'Home Page', 'edit_posts', 'post.php?post=5&action=edit', '', 'dashicons-admin-home', 6 ); } add_action( 'admin_menu', 'add_home_menu_page' );
This code will add a page named 'Home' to the backend dashboard menu.
Hide editor from specific page.
add_action( 'admin_init', 'hide_editor' ); function hide_editor() { // Get the Post ID. $post_id = $_GET['post'] ? $_GET['post'] : $_POST['post_ID'] ; if( !isset( $post_id ) ) return; // Hide the editor on the page titled 'Homepage' $homepgname = get_the_title($post_id); if($homepgname == 'Homepage'){ remove_post_type_support('page', 'editor'); } // Hide the editor on a page with a specific page template // Get the name of the Page Template file. $template_file = get_post_meta($post_id, '_wp_page_template', true); if($template_file == 'page-home.php'){ // the filename of the page template remove_post_type_support('page', 'editor'); } }