Hot answers tagged admin-menu
25
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
...
17
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 ...
10
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( ...
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 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.
6
Not really, no. You can override built-in PHP functions, but not user-defined functions.
However, all this function does is define a meta box. Why not define your own?
Once you've got your own meta box defined and added, you can call remove_meta_box to remove the standard one:
remove_meta_box( 'add-POSTTYPENAME', 'nav-menus', 'side');
The meta box is ...
6
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' => ...
6
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 ...
6
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,
...
6
Add an admin menu separator
Separators, if this question targets this, are the dividers of the admin menu that separate the menu into sections. Per default it's divided into a "publish" and an "administration" area.
Plugin for the rescue
Here's what we're going to have afterwards: A custom separator.
I wrote a pretty simple plugin that I run as ...
5
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' );
...
5
Your menu slug (5th parameter) can't be the same across multiple pages, and it obviously can't have an & in it, but you can have all the pages you want call the same callback function (the last param).
add_submenu_page('upload_manage', "Programs", "Programs", 'manage_options', 'manage-programs', "manage_data");
add_submenu_page('upload_manage', ...
5
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 ...
5
here is the simplest implementation I know of since there is no real API:
//add the needed scripts and styles
add_action('admin_enqueue_scripts', 'wpse_46028_enqueue_admin_scripts');
function wpse_46028_enqueue_admin_scripts() {
wp_enqueue_style('wp-pointer');
wp_enqueue_script('wp-pointer');
//hook the pointer
...
5
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 ...
5
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 ...
4
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
4
Something like this should work. $handle should be the menu's slug; set $sub to true to search submenus (defaults to top level menus):
function find_my_menu_item( $handle, $sub = false; ){
if( !is_admin() || (defined('DOING_AJAX') && DOING_AJAX) )
return false;
global $menu, $submenu;
$check_menu = $sub ? $submenu : $menu;
if( empty( ...
4
This should remove support for comments on your site:
add_action('admin_menu', 'remove_comment_support');
function remove_comment_support() {
remove_post_type_support( 'post', 'comments' );
remove_post_type_support( 'page', 'comments' );
}
I don't know if it will hide every mention of comments in the admin section, though. The "Right Now" box on ...
4
I would do this when you call add_options_page(), not later. It's always better to do this with the supported API instead of playing with the internal structures.
The plugin updater periodically checks the plugin status and then saves the result in a transient. This means that it only reads this cached status when the menu is created, it doesn't do the full ...
4
It makes sense that if it's faster to use a new table for a thousand entries, it must also be faster for tens or hundreds of entries.
Performance is not about the pure number rows – the real amount of data and their structure counts. Usually, you use just the theme mod API. Your theme data is on a predictable place and can easily exported or changed by ...
4
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 ...
4
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 ...
4
There's a much easier way for setting the current menu context - the parent_file filter.
add_filter( 'parent_file', array( 'WPSE_59050', 'parent_file' ) );
add_action( 'admin_menu', array( 'WPSE_59050', 'admin_menu' ) );
class WPSE_59050
{
/**
* The title of the post to add our menu item for.
*/
const POST_TITLE = 'My Post Title';
...
4
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,
...
4
They are undefined because the functions don't exist right when plugins (or themes) are loaded -- the admin area includes have not happened yet.
If you want to register settings fields it's best to hook into admin_init to do so.
In short, you can fix your class by doing this:
<?php
class mySettings {
public function __construct() {
...
4
add_action( 'admin_head', 'custom_post_type_icon' );
function custom_post_type_icon() {
?>
<style type="text/css" media="screen">
#menu-posts-intranet-pages .wp-menu-image {
background: url("PATH TO SMALL ICON") no-repeat 6px 6px !important;
}
#menu-posts-intranet-pages:hover .wp-menu-image, ...
4
Wordpress SEO
If you want to remove the admin menu:
you can do that with:
function hide_wpseo() {
remove_action('admin_menu', 'zeo_options_menu');
}
add_action( 'init', 'hide_wpseo');
where it will be removed for all users.
WordPress SEO by Yoast
To hide the admin menu:
and the admin menu bar:
one can use:
function hide_yoastseo() {
...
3
I personally just add a menu link and in the function for it handle the form. With $_SERVER['REQUEST_URI'] as the action. Example below.
add_action("admin_menu", "menu" );
function menu(){
add_menu_page('Test form', 'Test form', 'manage_options', 'show_form' );
}
function show_form(){
if ( $_SERVER["REQUEST_METHOD"] == "POST" ){
print ...
3
Hi @Roland:
I think the issue may be in your call to add_submenu_page():
add_submenu_page('wpsc-sales-logs',...
The first parameter needs to be a reference to your Menu Page's "slug", i.e. if you use 'edit.php' instead you'll see that you get a menu option under the "Posts" menu page:
add_submenu_page('edit.php','WPEC - Group Pricing','Group Pricing', ...
Only top voted, non community-wiki answers of a minimum length are eligible