Hot answers tagged

48

Here's the process to change the labels (I changed posts to "contacts" in my example) function change_post_menu_label() { global $menu; global $submenu; $menu[5][0] = 'Contacts'; $submenu['edit.php'][5][0] = 'Contacts'; $submenu['edit.php'][10][0] = 'Add Contacts'; $submenu['edit.php'][15][0] = 'Status'; // Change name for categories ...


32

The problem with @tollmanz answer is that since you're hooking off of the -print-styles and -print-scripts hooks, you must generate the HTML to load your scripts manually. This is not optimal, since you don't get the nice dependency and versioning that comes with wp_enqueue_script() and wp_enqueue_style(). It also doesn't let you put things in the footer if ...


25

Here's a quick and dirty way to get what you want. Background WordPress stores admin menu sections in a global array called $menu. To add a separator you add an element to the $menu array using an index that is between the indexes of the options that you want to separate. Using the add_admin_menu_separator() function So I've written a function to ...


24

Otto has suggested a fix in Chrome itself until the bug is resolved: Go to chrome://flags/#disable-slimming-paint Enable the "Disable slimming paint" option. Ensure that the "Enable slimming paint" option below it is not turned on. Relaunch Chrome. If you don't want to take this approach you can fix this with CSS: function chromefix_inline_css() { ...


23

You need to use the right hooks (which are not always the same as the URLs/slugs), and it doesn't hurt to use a hook that runs later (e.g., admin_init): add_action( 'admin_init', 'wpse_136058_remove_menu_pages' ); function wpse_136058_remove_menu_pages() { remove_menu_page( 'edit.php?post_type=acf' ); remove_menu_page( 'wpcf7' ); } You can use ...


21

Yes. When you register your post type you need to set show_in_menu to the page you would like it displayed on. Adding a custom post type as a sub-menu of Posts Here we set the "movies" post type to be included in the sub-menu under Posts. register_post_type( 'movies', array( 'labels' => array( 'name' => __( ...


19

Here is a list of all of the above answers and a removal of the admin bar link. Just add it to your themes function file or make it a plugin. I will mark this as a community wiki as everyone's answer is right just no one added it all together. <?php // Removes from admin menu add_action( 'admin_menu', 'my_remove_admin_menus' ); function ...


17

add_menu_page and add_submenu_page both return the page's "hook suffix", which can be used to identify the page with certain hooks. As such, you can use that suffix in combination with the variable hooks admin_print_styles-{$hook_suffix} and admin_print_scripts-{$hook_suffix} to specifically target these pages. function my_menu() { $menu = add_menu_page( ...


13

Codex - Register Post Type See the capability_type and capabilities arguments for register_post_type. You can pass the capabilities argument an array of capabilities to map to the necessary caps, here's an example of the args array with custom capabilities. $args = array( 'labels' => $labels, 'public' => true, 'publicly_queryable' => ...


13

If you use get_current_screen(), you can detect what the page you're on is. There is an example in the codex article that I linked which shows how to use get_current_screen() with add_options_page(), this method will work for any admin page.


11

The correct hook to use is admin_menu and then create a function to remove the menus you want to remove. The following 2 functions remove all the menus. add_action( 'admin_menu', 'remove_admin_menus' ); add_action( 'admin_menu', 'remove_admin_submenus' ); //Remove top level admin menus function remove_admin_menus() { remove_menu_page( ...


10

I made this work iterating through a post types list, and pinpointing the correct $menu key for the post type using a secondary function (instead of manually iterating through the $menu object). Function reference: get_post_types and wp_count_posts. add_action( 'admin_menu', 'pending_posts_bubble_wpse_89028', 999 ); function ...


10

You probably need to set the add_action priority to a higher number and target those two new links specifically like so: add_action( 'admin_menu', 'my_remove_menu_pages', 999 ); function my_remove_menu_pages() { remove_menu_page( 'edit.php' ); //Posts remove_menu_page( 'upload.php' ); //Media remove_menu_page( ...


9

Yes, this capability is available with register_post_type, via the show_in_menu argument, but whether or not the particular plugin you are using supports this I don't know. add_action( 'init', 'wpa70679_custom_types' ); function wpa70679_custom_types() { register_post_type( 'parent_type', array( 'public' => true, ...


8

Update: reading mike's answer again got me thinking that you can add a new capability to a role and use that as you removal condition, so: // first add your role the capability like so // get the "author" role object $role = get_role( 'administrator' ); // add "see_all_menus" to this role object $role->add_cap( 'see_all_menus' ); ...


8

Here's how I recently added a custom taxonomy to the media library as a sortable column: // Add a new column add_filter('manage_media_columns', 'add_topic_column'); function add_topic_column($posts_columns) { $posts_columns['att_topic'] = _x('Topic', 'column name'); return $posts_columns; } // Register the column as sortable function ...


8

I've not worked with the admin-bar before. However, I found your question interesting and decided to take a look. If you add a function to handle the action hook 'admin_bar_menu' and set the priority to be higher than 70, you will have access to the raw admin_bar_menu nodes where you can modify the properties you are trying to access. Below is a detailed set ...


8

Doing this search, I've found this fine answer by Chris_O. There's even a jQuery solution I proposed there. Anyway, the function remove_menu_page('edit.php'); only removes the Posts menu. But, as we learn from Chris answer, remove_menu_page('edit.php?post_type=athletes'); removes the Custom Post Type menu. To really block access to the URL, as we're ...


8

You need just two steps: Hook into the action admin_menu, register the page with a callback function to print the content. In your callback function load the file from plugin_dir_path( __FILE__ ) . "included.html". Demo code: add_action( 'admin_menu', 'wpse_91693_register' ); function wpse_91693_register() { add_menu_page( 'Include Text', ...


8

Add this to your theme's functions.php: add_action( 'admin_bar_menu', 'make_parent_node', 999 ); function make_parent_node( $wp_admin_bar ) { if ( ! is_admin() ) { return; } // end function if not in admin back-end, credit @Rarst $args = array( 'id' => 'view-site', // id of the existing child node (View Site) 'title' => ...


7

you can create a function that redirects to the front-end like this: function redirect_home_987(){ wp_redirect( home_url() ); exit; } and call that function in WordPress default add_menu_page function like this: add_menu_page( 'redirecting', 'View Site', 'read', 'my-top-level-handle', 'redirect_home_987'); Hope this helps


7

this might work: add_filter('custom_menu_order', 'my_custom_menu_order'); add_filter('menu_order', 'my_custom_menu_order'); function my_custom_menu_order($menu_ord) { if (!$menu_ord) return true; return array( 'index.php', // the dashboard link 'edit.php?post_type=custom_post_type', 'edit.php?post_type=page', ...


7

If you wrote your code correctly, then delete_option would be the correct way. The question isn't how to clear the option; the question is how to structure your code such that the "option does not exist" case is a valid case. Think about it. The first time you start this code, that option isn't going to exist at all, right? Your code should be perfectly ...


7

You need to add your hook at the end of the queue and then remove menu by slug: function remove_menu_links() { if( !current_user_can( 'manage_options' ) ) { remove_menu_page( 'gf_edit_forms' ); // this is the pages url } } add_action( 'admin_menu', 'remove_menu_links', 9999 ); If you want to remove submenu you need to use following ...


7

On the function to register a new custom post type can you set this CPT as Submenu to a exist menu item. Use the param show_in_menu A example: register_post_type( 'issue', apply_filters( 'wpit_register_issue_post_type', array( 'labels' => $issue_labels, 'rewrite' => $issue_rewrite, ...


7

From the docs on add_submenu_page(), you see that you can hide your submenu link from a top level menu item to which it belongs be setting the slug (1st argument) to null: add_action( 'admin_menu', 'register_my_custom_submenu_page' ); function register_my_custom_submenu_page() { add_submenu_page( null, 'My Custom Submenu Page', ...


7

function remove_submenu() { remove_submenu_page( 'edit.php', 'edit-tags.php?taxonomy=faq-topic&post_type=question' ); remove_submenu_page( 'edit.php', 'edit-tags.php?taxonomy=faq-tags&post_type=question' ); } add_action( 'admin_menu', 'remove_submenu', 999 ); Please read the Codex. remove_submenu_page() need two parameters and the right ...


7

Remember Apple's "Goto Fail"? Similar situation: Your code actually does this, when indentation is corrected: foreach ( $post_types as $post_type ) remove_meta_box('trackbacksdiv', $post_type, 'normal'); remove_meta_box('postcustom', $post_type, 'normal'); remove_meta_box('authordiv', $post_type, 'normal'); remove_meta_box('postexcerpt', ...


7

Here's an example of the data returned from the wp_get_update_data() function: Array ( [counts] => Array ( [plugins] => 3 [themes] => 2 [wordpress] => 0 [translations] => 0 [total] => 5 ) [title] => 3 Plugin Updates, 2 Theme Updates ) So the number of ...


7

Not complicated, but a little tricky to get timing right. Something like this should work, but you might need to experiment with priority to get the link to specific position on the bar: add_action( 'admin_bar_menu', function ( $wp_admin_bar ) { if ( ! is_admin() ) { return; } /** @var WP_Admin_Bar $wp_admin_bar */ ...



Only top voted, non community-wiki answers of a minimum length are eligible