[wp-trac] [WordPress Trac] #47125: Admin: clarify the "Add New" links for better accessibility
WordPress Trac
noreply at wordpress.org
Tue Aug 20 19:37:40 UTC 2024
#47125: Admin: clarify the "Add New" links for better accessibility
-------------------------------------+-------------------------------------
Reporter: afercia | Owner: joedolson
Type: defect (bug) | Status: closed
Priority: normal | Milestone: 6.4
Component: Administration | Version:
Severity: normal | Resolution: fixed
Keywords: has-screenshots has- | Focuses: ui, accessibility,
patch needs-dev-note commit | administration
-------------------------------------+-------------------------------------
Comment (by dilip2615):
[1]. Modify WordPress Admin Menu Items
For the admin menu, you can hook into the **admin_menu** action to change
the labels of the "Add New" menu items. Here's an example:
function customize_admin_menu_labels() {
global $menu, $submenu;
// Update "Posts" submenu
if (isset($submenu['edit.php'])) {
foreach ($submenu['edit.php'] as &$item) {
if ($item[0] == 'Add New') {
$item[0] = 'Add New Post';
}
}
}
// Update "Media" submenu
if (isset($submenu['upload.php'])) {
foreach ($submenu['upload.php'] as &$item) {
if ($item[0] == 'Add New') {
$item[0] = 'Add New Media';
}
}
}
// Update "Pages" submenu
if (isset($submenu['edit.php?post_type=page'])) {
foreach ($submenu['edit.php?post_type=page'] as &$item) {
if ($item[0] == 'Add New') {
$item[0] = 'Add New Page';
}
}
}
// Update "Plugins" submenu
if (isset($submenu['plugins.php'])) {
foreach ($submenu['plugins.php'] as &$item) {
if ($item[0] == 'Add New') {
$item[0] = 'Add New Plugin';
}
}
}
// Update "Users" submenu
if (isset($submenu['users.php'])) {
foreach ($submenu['users.php'] as &$item) {
if ($item[0] == 'Add New') {
$item[0] = 'Add New User';
}
}
}
}
add_action('admin_menu', 'customize_admin_menu_labels');
[2]. Modify Admin Page Links
If there are "Add New" links within admin pages (e.g., on the Posts,
Pages, Media, etc.), you can use a script to update these links
dynamically. Here's a basic example using jQuery:
function customize_admin_add_new_links() {
?>
<script type="text/javascript">
jQuery(document).ready(function($) {
// Update the "Add New" links
$('a.add-new-h2').each(function() {
var href = $(this).attr('href');
if (href.includes('post-new.php?post_type=post')) {
$(this).text('Add New Post');
} else if (href.includes('post-new.php?post_type=page')) {
$(this).text('Add New Page');
} else if (href.includes('post-
new.php?post_type=attachment')) {
$(this).text('Add New Media');
} else if (href.includes('plugin-install.php')) {
$(this).text('Add New Plugin');
} else if (href.includes('user-new.php')) {
$(this).text('Add New User');
}
});
});
</script>
<?php
}
add_action('admin_footer', 'customize_admin_add_new_links');
--
Ticket URL: <https://core.trac.wordpress.org/ticket/47125#comment:24>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list